Linux Documentation
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: "David Hildenbrand (Arm)" <david@kernel.org>
Cc: Muchun Song <muchun.song@linux.dev>,
	Oscar Salvador <osalvador@kernel.org>,
	Hongfu Li <lihongfu@kylinos.cn>,
	Jinmeng Zhou <jinmengzhou22@gmail.com>,
	Mina Almasry <almasrymina@google.com>,
	Davidlohr Bueso <dave@stgolabs.net>,
	Naoya Horiguchi <nao.horiguchi@gmail.com>,
	"Liam R. Howlett" <liam@infradead.org>,
	Vlastimil Babka <vbabka@kernel.org>,
	Mike Rapoport <rppt@kernel.org>, Michal Hocko <mhocko@suse.com>,
	Jonathan Corbet <corbet@lwn.net>,
	Shuah Khan <skhan@linuxfoundation.org>,
	Randy Dunlap <rdunlap@infradead.org>,
	Vivek Kasireddy <vivek.kasireddy@intel.com>,
	Mel Gorman <mgorman@suse.de>, Hugh Dickins <hughd@google.com>,
	Baolin Wang <baolin.wang@linux.alibaba.com>,
	Dave Airlie <airlied@redhat.com>, Jason Gunthorpe <jgg@ziepe.ca>,
	Andy Whitcroft <apw@canonical.com>,
	Roman Gushchin <roman.gushchin@linux.dev>,
	Barry Song <baohua@kernel.org>,
	Andrea Arcangeli <aarcange@redhat.com>,
	Lorenzo Stoakes <ljs@kernel.org>,
	Suren Baghdasaryan <surenb@google.com>,
	Shakeel Butt <shakeel.butt@linux.dev>,
	Pedro Falcato <pfalcato@suse.de>, Jann Horn <jannh@google.com>,
	Guillaume Morin <guillaume@morinfr.org>,
	Yang Shi <shy828301@gmail.com>,
	James Houghton <jthoughton@google.com>,
	Rik van Riel <riel@surriel.com>, Harry Yoo <harry@kernel.org>,
	Lance Yang <lance.yang@linux.dev>,
	Axel Rasmussen <axelrasmussen@google.com>,
	Peter Xu <peterx@redhat.com>, Sasha Levin <sashal@kernel.org>,
	Kiryl Shutsemau <kas@kernel.org>,
	Christian Brauner <brauner@kernel.org>,
	"Steven Rostedt (Google)" <rostedt@goodmis.org>,
	Hongbo Li <lihongbo22@huawei.com>,
	Gregory Price <gourry@gourry.net>, Zi Yan <ziy@nvidia.com>,
	Joshua Hahn <joshua.hahnjy@gmail.com>,
	Rakie Kim <rakie.kim@sk.com>,
	Ying Huang <ying.huang@linux.alibaba.com>,
	Matthew Brost <matthew.brost@intel.com>,
	Byungchul Park <byungchul@sk.com>,
	Alistair Popple <apopple@nvidia.com>,
	Andi Kleen <ak@linux.intel.com>,
	David Rientjes <rientjes@google.com>,
	Joern Engel <joern@lazybastard.org>,
	"Aneesh Kumar K.V" <aneesh.kumar@kernel.org>,
	linux-mm@kvack.org, linux-doc@vger.kernel.org,
	Gerd Hoffmann <kraxel@redhat.com>,
	linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
	Johannes Weiner <hannes@cmpxchg.org>,
	Chris Mason <mason@kernel.org>, Jiaqi Yan <jiaqiyan@google.com>,
	Sashiko <sashiko-bot@kernel.org>,
	stable@vger.kernel.org
Subject: Re: [PATCH v2 00/35] mm/hugetlb: various fixes (2)
Date: Thu, 3 Dec 2026 11:11:47 -0800	[thread overview]
Message-ID: <20261203111147.70cf4c99e51503134c8d5ae1@linux-foundation.org> (raw)
In-Reply-To: <20261203-hugetlb_fixes_2-v2-0-9bbeabb555d2@kernel.org>

On Thu, 03 Dec 2026 12:37:23 +0100 "David Hildenbrand (Arm)" <david@kernel.org> 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 <resv_map_helpers>` 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));
_


      parent reply	other threads:[~2026-12-03 19:11 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03 11:37 [PATCH v2 00/35] mm/hugetlb: various fixes (2) David Hildenbrand (Arm)
2026-12-03 11:37 ` [PATCH v2 01/35] mm/hugetlb: charge the copy made at fork to the parent David Hildenbrand (Arm)
2026-12-03 11:37 ` [PATCH v2 02/35] mm/hugetlb: restore the reservation if vma_needs_reservation() fails David Hildenbrand (Arm)
2026-12-03 11:37 ` [PATCH v2 03/35] mm/hugetlb: restore the reservation when racing with another reservation David Hildenbrand (Arm)
2026-12-03 11:37 ` [PATCH v2 04/35] mm/hugetlb: return the reservation to the subpool on error David Hildenbrand (Arm)
2026-12-03 11:37 ` [PATCH v2 05/35] mm/hugetlb: report reservations that we actually added from hugetlb_reserve_pages() David Hildenbrand (Arm)
2026-12-03 11:37 ` [PATCH v2 06/35] mm/hugetlb: keep HPAGE_RESV_UNMAPPED when forking David Hildenbrand (Arm)
2026-12-03 11:37 ` [PATCH v2 07/35] mm/hugetlb: always mark new page cache folios migratable David Hildenbrand (Arm)
2026-12-03 11:37 ` [PATCH v2 08/35] mm/memfd: mark new hugetlb " David Hildenbrand (Arm)
2026-12-03 11:37 ` [PATCH v2 09/35] mm/hugetlb: free surplus folios of other nodes on free David Hildenbrand (Arm)
2026-12-03 11:37 ` [PATCH v2 10/35] mm/hugetlb: wait for deferred frees before failing an allocation David Hildenbrand (Arm)
2026-12-03 11:37 ` [PATCH v2 11/35] mm/hugetlb_cma: reset hugetlb_cma_size if the arch doesn't support it David Hildenbrand (Arm)
2026-12-03 11:37 ` [PATCH v2 12/35] mm/hugetlb: fix truncated copy result in UFFDIO_COPY David Hildenbrand (Arm)
2026-12-03 11:37 ` [PATCH v2 13/35] fs/proc/task_mmu: don't clear VM_SOFTDIRTY on hugetlb VMAs David Hildenbrand (Arm)
2026-12-03 11:37 ` [PATCH v2 14/35] hugetlbfs: fix integer overflow when punching holes David Hildenbrand (Arm)
2026-12-03 11:37 ` [PATCH v2 15/35] hugetlbfs: don't zero poisoned pages in a hole punch David Hildenbrand (Arm)
2026-12-03 11:37 ` [PATCH v2 16/35] hugetlbfs: fix deadlock between hole punching and memory failure David Hildenbrand (Arm)
2026-12-03 11:37 ` [PATCH v2 17/35] hugetlbfs: don't overflow the pseudo VMA address in fallocate() David Hildenbrand (Arm)
2026-12-03 11:37 ` [PATCH v2 18/35] hugetlbfs: don't overflow the end of the unmap range on 32-bit David Hildenbrand (Arm)
2026-12-03 11:37 ` [PATCH v2 19/35] hugetlbfs: recheck the vma range after the lock wait David Hildenbrand (Arm)
2026-12-03 11:37 ` [PATCH v2 20/35] mm/hugetlb: don't zap non-present entries when unmapping a folio David Hildenbrand (Arm)
2026-12-03 11:37 ` [PATCH v2 21/35] hugetlbfs: don't skip private VMAs when unmapping on truncation David Hildenbrand (Arm)
2026-12-03 11:37 ` [PATCH v2 22/35] mm/hugetlb: serialize private faults with truncation David Hildenbrand (Arm)
2026-12-03 11:37 ` [PATCH v2 23/35] mm/hugetlb: check EOF for UFFDIO_COPY and UFFDIO_POISON David Hildenbrand (Arm)
2026-12-03 11:37 ` [PATCH v2 24/35] hugetlbfs: seal SHM_HUGETLB files against growth David Hildenbrand (Arm)
2026-12-03 11:37 ` [PATCH v2 25/35] hugetlbfs: zero all hugetlbfs-specific fields of new inodes David Hildenbrand (Arm)
2026-12-03 11:37 ` [PATCH v2 26/35] mm/rmap: don't fail unmapping hugetlb folios from private VMAs David Hildenbrand (Arm)
2026-12-03 11:37 ` [PATCH v2 27/35] mm/hugetlb: only check PMD table sharing for PMD-sized folios David Hildenbrand (Arm)
2026-12-03 11:37 ` [PATCH v2 28/35] mm/migrate: check hugetlb PMD sharing in move_pages() David Hildenbrand (Arm)
2026-12-03 11:37 ` [PATCH v2 29/35] mm/hugetlb: don't share page tables of a VMA during mprotect() David Hildenbrand (Arm)
2026-12-03 11:37 ` [PATCH v2 30/35] mm/hugetlb: unshare PMDs of a split VMA if allocating its lock fails David Hildenbrand (Arm)
2026-12-03 11:37 ` [PATCH v2 31/35] mm/hugetlb: count migration entries at fork and unmap David Hildenbrand (Arm)
2026-12-03 11:37 ` [PATCH v2 32/35] mm/hugetlb: stop accounting HugetlbPages once PMD tables were shared David Hildenbrand (Arm)
2026-12-03 11:37 ` [PATCH v2 33/35] mm/hugetlb_cgroup: track in-use folios per cgroup David Hildenbrand (Arm)
2026-12-03 11:37 ` [PATCH v2 34/35] mm/hugetlb_cgroup: charge faults to mm->owner David Hildenbrand (Arm)
2026-12-03 11:37 ` [PATCH v2 35/35] mm/hugetlb: resolve protnone faults without a uffd bit David Hildenbrand (Arm)
2026-12-03 19:11 ` Andrew Morton [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261203111147.70cf4c99e51503134c8d5ae1@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=aarcange@redhat.com \
    --cc=airlied@redhat.com \
    --cc=ak@linux.intel.com \
    --cc=almasrymina@google.com \
    --cc=aneesh.kumar@kernel.org \
    --cc=apopple@nvidia.com \
    --cc=apw@canonical.com \
    --cc=axelrasmussen@google.com \
    --cc=baohua@kernel.org \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=brauner@kernel.org \
    --cc=byungchul@sk.com \
    --cc=corbet@lwn.net \
    --cc=dave@stgolabs.net \
    --cc=david@kernel.org \
    --cc=gourry@gourry.net \
    --cc=guillaume@morinfr.org \
    --cc=hannes@cmpxchg.org \
    --cc=harry@kernel.org \
    --cc=hughd@google.com \
    --cc=jannh@google.com \
    --cc=jgg@ziepe.ca \
    --cc=jiaqiyan@google.com \
    --cc=jinmengzhou22@gmail.com \
    --cc=joern@lazybastard.org \
    --cc=joshua.hahnjy@gmail.com \
    --cc=jthoughton@google.com \
    --cc=kas@kernel.org \
    --cc=kraxel@redhat.com \
    --cc=lance.yang@linux.dev \
    --cc=liam@infradead.org \
    --cc=lihongbo22@huawei.com \
    --cc=lihongfu@kylinos.cn \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ljs@kernel.org \
    --cc=mason@kernel.org \
    --cc=matthew.brost@intel.com \
    --cc=mgorman@suse.de \
    --cc=mhocko@suse.com \
    --cc=muchun.song@linux.dev \
    --cc=nao.horiguchi@gmail.com \
    --cc=osalvador@kernel.org \
    --cc=peterx@redhat.com \
    --cc=pfalcato@suse.de \
    --cc=rakie.kim@sk.com \
    --cc=rdunlap@infradead.org \
    --cc=riel@surriel.com \
    --cc=rientjes@google.com \
    --cc=roman.gushchin@linux.dev \
    --cc=rostedt@goodmis.org \
    --cc=rppt@kernel.org \
    --cc=sashal@kernel.org \
    --cc=sashiko-bot@kernel.org \
    --cc=shakeel.butt@linux.dev \
    --cc=shy828301@gmail.com \
    --cc=skhan@linuxfoundation.org \
    --cc=stable@vger.kernel.org \
    --cc=surenb@google.com \
    --cc=vbabka@kernel.org \
    --cc=vivek.kasireddy@intel.com \
    --cc=ying.huang@linux.alibaba.com \
    --cc=ziy@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox