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=1796325238; b=P4O/9QsM8J8WVSC8sJh8TD/mGZpJCnbRALQm0NoOso2XrKyAvtE3R6DCRVtILoswUy5O pWkQfaOPifu1Vr4mzQrWAzG6YWQ6xiL7tNSKOIZ/cGNrS3ko2xgZb9AodeskedjxSdkju MJg6BZ+naQ+A40xgeEoEWSSBauqwdnY9STlFD7TNRqWUtD2EKDa3k9CcTJ4BsTsiOgT/E yTQSu3Ze3iFEnGLDOMOP7skxdpcpR/5V//s/XYjwE5602DAHbWIOntuTeKmu8Jq4JibLu EULEMQhQ5JNRlyzuFgA6cYunQg6ziY+4DoMcKFarmnbvh8cHrQphijwy38BIrml2eTA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796325238; h=Received:DKIM-Signature:Date:To:From:In-Reply-To:References:Subject: Message-Id; bh=7Ffa2z7HJW4DhfhB1ZRJvvIeTktyiNWCKFt3yVQAtow=; b=VxRjPTW+FjV5DpK+oAXWTZIUvW//2jBccRh3aX7tQ5qaAOmQEFqnqro+f4DepJociS1v +U7J36LqiSYSd9VPfc5UuRcJQRUrwJJWQL67Hcmtpirw8X6Mar3yS1/oTIQgmSrXFJN5v F16SQtegCkZYRNiuxhDMcm3b7PXxGbtoI6hPKy6WVjjprGA2aNLzF077cVEGSS3RC+ZFL 36qhJdyd5jXLdC8cl73rQTpg7j9WgrJQE/Ks4oSHgLZEOarFoct5CK4T3vsAbRvSovM5l 032nIFwHABu0ONK5Gd5dtsqwxuhti9M/D1Sbd0XdYwk43UfgnhY/BZejWKUnkEqGw7A== 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=Ai3WZu37; 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 35FB1606A334 for ; Thu, 3 Dec 2026 19:13:58 +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=Ai3WZu37 Received: by smtp.kernel.org (Postfix) with ESMTPSA id E05261F0092C; Thu, 3 Dec 2026 19:13:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=korg; t=1796325238; bh=7Ffa2z7HJW4DhfhB1ZRJvvIeTktyiNWCKFt3yVQAtow=; h=Date:To:From:In-Reply-To:References:Subject; b=Ai3WZu37yL0mlUAPfS9GTHOaUBYL+LV8lCL+9gLpv8uWaAVPM62HKbO46xd9ChlOe oHhSXOtisvBNgGJ5Umu4h+ek+vAtDXUoykk8A0l7SZQHykePvqcMY7vOZcyNSp8yHL iUJylLp+sEyyM4Sv+A2I2JpQjHkOklDePr7yLljU= Date: Thu, 03 Dec 2026 11:13:57 -0800 To: mm-commits@vger.kernel.org,david@kernel.org,akpm@linux-foundation.org From: Andrew Morton In-Reply-To: <20261203-hugetlb_fixes_2-v2-22-9bbeabb555d2@kernel.org> References: <20261203-hugetlb_fixes_2-v2-22-9bbeabb555d2@kernel.org> Subject: + mm-hugetlb-serialize-private-faults-with-truncation.patch added to mm-unstable branch Message-Id: <20261203191357.E05261F0092C@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 patch titled Subject: mm/hugetlb: serialize private faults with truncation has been added to the -mm mm-unstable branch. Its filename is mm-hugetlb-serialize-private-faults-with-truncation.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-hugetlb-serialize-private-faults-with-truncation.patch This patch will later appear in the mm-unstable branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next via various branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm and is updated there most days ------------------------------------------------------ From: "David Hildenbrand (Arm)" Subject: mm/hugetlb: serialize private faults with truncation Date: Thu, 03 Dec 2026 12:37:45 +0100 When we fault in a folio in a MAP_PRIVATE hugetlb mapping at an index without a page cache folio, hugetlb_no_page() checks that the index is not beyond EOF, allocates a new anonymous folio and maps it. Truncation first updates i_size under the invalidate lock, and then unmaps the truncated range from all VMAs. For page cache folios, we recently started rechecking EOF under filemap_invalidate_lock_shared() to handle exactly that. However, nothing serializes the allocation of anonymous folios with truncation: if truncation unmaps the range after we checked EOF, but before we mapped the new folio, the folio stays mapped beyond EOF. Consequently, accessing the truncated range does not raise SIGBUS, and the process keeps the folio mapped until it unmaps it. Reproduced by artificially delaying hugetlb_no_page() before allocating the folio, while another thread truncates the file: the page beyond EOF stays mapped. Let's fix it by also rechecking EOF under the invalidate lock for anonymous folios, and holding it until we mapped the folio, such that truncation will unmap it. Like faults in shared mappings, faults in private mappings now briefly take the invalidate lock in read mode, and might have to wait for a concurrent truncation. Which seems to be the right thing to do. This has low urgency, as it requires racing a page fault in a private mapping with truncation. No need to CC stable. Link: https://patch.msgid.link/20261203-hugetlb_fixes_2-v2-22-9bbeabb555d2@kernel.org Fixes: fa27759af4a6 ("hugetlb: clean up code checking for fault/truncation races") Signed-off-by: David Hildenbrand (Arm) Signed-off-by: Andrew Morton Cc: Muchun Song Cc: Oscar Salvador Cc: Hongfu Li Cc: Jinmeng Zhou Cc: Mina Almasry Cc: Davidlohr Bueso Cc: Naoya Horiguchi Cc: Liam R. Howlett Cc: Vlastimil Babka Cc: Mike Rapoport Cc: Michal Hocko Cc: Jonathan Corbet Cc: Shuah Khan Cc: Randy Dunlap Cc: Vivek Kasireddy Cc: Mel Gorman Cc: Hugh Dickins Cc: Baolin Wang Cc: Dave Airlie Cc: Jason Gunthorpe Cc: Andy Whitcroft Cc: Roman Gushchin Cc: Barry Song Cc: Andrea Arcangeli Cc: Lorenzo Stoakes Cc: Suren Baghdasaryan Cc: Shakeel Butt Cc: Pedro Falcato Cc: Jann Horn Cc: Guillaume Morin Cc: Yang Shi Cc: James Houghton Cc: Rik van Riel Cc: Harry Yoo Cc: Lance Yang Cc: Axel Rasmussen Cc: Peter Xu Cc: Sasha Levin Cc: Kiryl Shutsemau Cc: Christian Brauner Cc: Steven Rostedt Cc: Hongbo Li 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: Andi Kleen Cc: David Rientjes Cc: Joern Engel Cc: Aneesh Kumar K.V Cc: Gerd Hoffmann Cc: Johannes Weiner Cc: Chris Mason Cc: Jiaqi Yan mm/hugetlb.c | 25 +++++++++++++++---------- mm/rmap.c | 2 +- 2 files changed, 16 insertions(+), 11 deletions(-) --- a/mm/hugetlb.c~mm-hugetlb-serialize-private-faults-with-truncation +++ a/mm/hugetlb.c @@ -5977,6 +5977,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); @@ -6036,15 +6037,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)) { /* @@ -6063,8 +6068,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); @@ -6085,10 +6088,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; @@ -6187,6 +6190,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); /* --- a/mm/rmap.c~mm-hugetlb-serialize-private-faults-with-truncation +++ 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) */ _ Patches currently in -mm which might be from david@kernel.org are 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 mm-filemap-avoid-retrying-faults-on-uffd-wp-markers.patch mm-hugetlb-restore-the-reservation-if-vma_needs_reservation-fails.patch mm-hugetlb-restore-the-reservation-when-racing-with-another-reservation.patch mm-hugetlb-return-the-reservation-to-the-subpool-on-error.patch mm-hugetlb-report-reservations-that-we-actually-added-from-hugetlb_reserve_pages.patch mm-hugetlb-keep-hpage_resv_unmapped-when-forking.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 mm-hugetlb-wait-for-deferred-frees-before-failing-an-allocation.patch mm-hugetlb_cma-reset-hugetlb_cma_size-if-the-arch-doesnt-support-it.patch fs-proc-task_mmu-dont-clear-vm_softdirty-on-hugetlb-vmas.patch hugetlbfs-fix-integer-overflow-when-punching-holes.patch hugetlbfs-dont-zero-poisoned-pages-in-a-hole-punch.patch hugetlbfs-dont-overflow-the-pseudo-vma-address-in-fallocate.patch hugetlbfs-dont-overflow-the-end-of-the-unmap-range-on-32-bit.patch hugetlbfs-dont-skip-private-vmas-when-unmapping-on-truncation.patch mm-hugetlb-serialize-private-faults-with-truncation.patch mm-hugetlb-check-eof-for-uffdio_copy-and-uffdio_poison.patch hugetlbfs-zero-all-hugetlbfs-specific-fields-of-new-inodes.patch mm-rmap-dont-fail-unmapping-hugetlb-folios-from-private-vmas.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 mm-hugetlb_cgroup-charge-faults-to-mm-owner.patch