From: Chris Mason When the owner of a private hugetlb mapping fails to allocate a folio for COW, unmap_ref_private() unmaps the old folio from the forked children, and marks them with HPAGE_RESV_UNMAPPED, so they get a SIGBUS on their next access. hugetlb_unmap_range() is supposed to only unmap that folio, but it clears non-present page table entries unconditionally. A child can silently lose its COWed folio while it is getting migrated, or a hwpoison entry or uffd poison marker, without HPAGE_RESV_UNMAPPED getting set. Consequently, it would not SIGBUS on the next access. Let's fix it by ignoring non-present entries when unmapping a folio. As the folio is locked, migration entries of that folio do not apply. This has low urgency, as it requires a failing COW allocation in the owner racing with migration or memory failure in the child. Let's not CC stable. Fixes: 8c4894c6bc79 ("hwpoison, hugetlbfs: fix "bad pmd" warning in unmapping hwpoisoned hugepage") Signed-off-by: Chris Mason [ david: adjust comment and description ] Signed-off-by: David Hildenbrand (Arm) --- mm/hugetlb.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index befa2670cb03f..2c13349863bd8 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -5457,6 +5457,14 @@ static void hugetlb_unmap_range(struct mmu_gather *tlb, * unmapped and its refcount is dropped, so just clear pte here. */ if (unlikely(!pte_present(pte))) { + /* + * If we have a folio provided, we only care about + * present page table entries (folio is locked). + */ + if (folio_provided) { + spin_unlock(ptl); + continue; + } /* * If the pte was wr-protected by uffd-wp in any of the * swap forms, meanwhile the caller does not want to -- 2.56.1