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=1796324394; b=wKV+pDImUK7zt3r2vtvPc7GtkkvxbyQIH6C5urOqurf64wJ6Lxc91baUF7YJ1UrqctXV 2/LKwaV4pd3T8vjyq83uLKIw6nsnaq6hxBLnW3sjAGxMA1ytKgBpMHjiqi3s5Ju0R2fWG 1j3EOFxz1pruOZ7iYkBm2PmmDrmn8CSLrJe8l31Aj8TCL42EYPIfPyI+8YEukgmCQI1p3 oMgj7oSxZsouEfQR9kHSxYIhv5AlQWKuzw+O31z4n+hszn5DxYBYdokkljty++6CygwRn TtIR5s0Df8GA8RhyfnwBclgmb9uwiKJEKx14z1ATbE7BrAqsZuHPWa8VK0/xIYA9FnA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796324394; h=Received:DKIM-Signature:Date:To:From:In-Reply-To:References:Subject: Message-Id; bh=vRu0EcD3Hu8b/9/bW7Aa2ld0CAHcPwmKUm5oKfiudsg=; b=mdicDrYK4m3wYueEzByr2iv0NyOjLdanKFMH4kyMR5KE6KZfYNWeD4AvC1eXqnE8RFoK Pr0w/qg/Hby1BSJzIqiNcUkYeYv3jAlEhe1taTJ1+9nYKdgYAcDMrQcebnwN74mkBGBYf 8YxdIjGDX0ky5lhMM6RwxOpbgXYWUoVztAKAmELiIgtZlf7G74StaDmDCG2ujpCR1MpZj EdXT5s/rZ0Eyaez9yN8S5xsjYot45Ie8YDM0HZfuaW1B3p9k9zD/o8qIoYsveumHW5wrj YPcZuqd7gpbSyQp18gZGBs40ScdUU1vgeqmgDkWUthGcjkCoKQ3h3KqtlsHWNGxu5qA== 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=QH5uRY45; 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 85502606A322 for ; Thu, 3 Dec 2026 18:59:54 +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=QH5uRY45 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 21AD01F000C1; Thu, 3 Dec 2026 18:59:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=korg; t=1796324394; bh=vRu0EcD3Hu8b/9/bW7Aa2ld0CAHcPwmKUm5oKfiudsg=; h=Date:To:From:In-Reply-To:References:Subject; b=QH5uRY45+7t14KDLsW9guwLMYDNhXSPbI4nFnB3TtUIvwu0jRsihSZNTkxMSpcBxc HJHFTEyunh5o8dW3tF9ypv/hSSxA3Oo4F+cm8d/nErzUE0EQf1y6EPfC/Z1/Eobsaa G3fqP3euI8popVywDgYUORe6Rk+RQdnk5kcQq918= Date: Thu, 03 Dec 2026 10:59:53 -0800 To: mm-commits@vger.kernel.org,mason@kernel.org,akpm@linux-foundation.org From: Andrew Morton In-Reply-To: <20261125-hugetlb_fixes_2-v1-6-db27fd2f71a8@kernel.org> References: <20261125-hugetlb_fixes_2-v1-6-db27fd2f71a8@kernel.org> Subject: [to-be-updated] hugetlbfs-fix-deadlock-between-hole-punching-and-memory-failure.patch removed from -mm tree Message-Id: <20261203185954.21AD01F000C1@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: hugetlbfs: fix deadlock between hole punching and memory failure has been removed from the -mm tree. Its filename was hugetlbfs-fix-deadlock-between-hole-punching-and-memory-failure.patch This patch was dropped because an updated version will be issued ------------------------------------------------------ From: Chris Mason Subject: hugetlbfs: fix deadlock between hole punching and memory failure Date: Wed, 25 Nov 2026 23:33:04 +0100 Punching a hole that isn't aligned to the huge page size can deadlock against memory_failure() on a mapped folio at the edge of the hole. hugetlbfs_punch_hole() locks and zeroes the partial folios with i_mmap_rwsem held for write, following the hugetlbfs locking order documented in mm/rmap.c: i_mmap_rwsem before the folio lock. However, try_memory_failure_hugetlb() locks the folio first, and then collects the processes to kill under i_mmap_rwsem: hugetlbfs_punch_hole() try_memory_failure_hugetlb() ====================== ============================ i_mmap_lock_write() folio_lock() hugetlbfs_zero_partial_page() hwpoison_user_mappings() filemap_lock_hugetlb_folio() collect_procs_file() waits for the folio lock i_mmap_lock_read() waits for the writer In fact, the documentation is outdated: hugetlbfs_punch_hole() is the *only* one that still takes i_mmap_rwsem before the folio lock. All other scenarios always take the folio lock before the i_mmap_rwsem. Only memory failure can deadlock with the hole punch: * truncation and hole punching of full folios are serialized against it through the inode lock * unmap_ref_private() holds the lock of an anon folio, not of a page cache folio that the hole punch zeroes * migration only tries to take the i_mmap_rwsem. There is no need to zero the partial folios under i_mmap_rwsem. The lock only protects the VMA tree and PMD table sharing, nothing about zeroing; the inode lock and the folio lock are sufficient. Let's fix it by only holding i_mmap_rwsem while unmapping the full folios of the hole. Update the documented locking order in mm/rmap.c and the function comment above hugetlb_folio_mapping_lock_write(). hugetlb_folio_mapping_lock_write() could now take the lock unconditionally, but we leave that for a separate change. The order of the folio lock and i_mmap_rwsem now matches the one for other folios, which is nice. This has low urgency, as the race shouldn't really happen all that often in practice (never seen). [david@kernel.org: adjust comment and description] Link: https://patch.msgid.link/20261125-hugetlb_fixes_2-v1-6-db27fd2f71a8@kernel.org Fixes: 68d32527d340 ("hugetlbfs: zero partial pages during fallocate hole punch") Signed-off-by: Chris Mason 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: Jason Gunthorpe Cc: luojiajun Cc: Josef Bacik Cc: Daehyeon Ko <4ncienth@gmail.com> Cc: Ackerley Tng Cc: Jiaqi Yan Cc: fs/hugetlbfs/inode.c | 6 ++---- mm/hugetlb.c | 3 +-- mm/rmap.c | 4 ++-- 3 files changed, 5 insertions(+), 8 deletions(-) --- a/fs/hugetlbfs/inode.c~hugetlbfs-fix-deadlock-between-hole-punching-and-memory-failure +++ a/fs/hugetlbfs/inode.c @@ -684,8 +684,6 @@ static long hugetlbfs_punch_hole(struct return -EPERM; } - i_mmap_lock_write(mapping); - /* If range starts before first full page, zero partial page. */ if (offset < hole_start) hugetlbfs_zero_partial_page(h, mapping, @@ -693,10 +691,12 @@ static long hugetlbfs_punch_hole(struct /* Unmap users of full pages in the hole. */ if (hole_end > hole_start) { + i_mmap_lock_write(mapping); if (mapping_mapped(mapping)) hugetlb_vmdelete_list(mapping, hole_start >> PAGE_SHIFT, hole_end >> PAGE_SHIFT, 0); + i_mmap_unlock_write(mapping); } /* If range extends beyond last full page, zero partial page. */ @@ -704,8 +704,6 @@ static long hugetlbfs_punch_hole(struct hugetlbfs_zero_partial_page(h, mapping, hole_end, offset + len); - i_mmap_unlock_write(mapping); - /* Remove full pages from the file. */ if (hole_end > hole_start) remove_inode_hugepages(inode, hole_start, hole_end); --- a/mm/hugetlb.c~hugetlbfs-fix-deadlock-between-hole-punching-and-memory-failure +++ a/mm/hugetlb.c @@ -1871,8 +1871,7 @@ void init_new_hugetlb_folio(struct folio * Find and lock address space (mapping) in write mode. * * Upon entry, the folio is locked which means that folio_mapping() is - * stable. Due to locking order, we can only trylock_write. If we can - * not get the lock, simply return NULL to caller. + * stable. If we cannot get the lock immediately, we simply return NULL. */ struct address_space *hugetlb_folio_mapping_lock_write(struct folio *folio) { --- a/mm/rmap.c~hugetlbfs-fix-deadlock-between-hole-punching-and-memory-failure +++ a/mm/rmap.c @@ -49,8 +49,8 @@ * 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->i_mmap_rwsem (also used for hugetlb pmd sharing) - * folio_lock + * folio_lock + * mapping->i_mmap_rwsem (also used for hugetlb pmd sharing) */ #include _ Patches currently in -mm which might be from mason@kernel.org are mm-swap-fix-large-swap-in-across-swap-file-extents.patch hugetlbfs-do-not-grow-a-sealed-file-in-mmap.patch mm-hugetlb-keep-surplus-folios-that-are-reserved.patch mm-hugetlb-fix-reservation-leak-on-min_size=-mounts.patch mm-cachestat-count-each-page-only-once.patch mm-cachestat-restart-the-walk-after-each-entry.patch percpu-queue-the-balance-work-on-an-unbound-workqueue.patch mm-vma-fix-uncharge-after-failed-stack-relocation.patch mm-mremap-apply-the-mmap-offset-limits-on-expansion.patch mm-mremap-respect-guard-gaps-on-in-place-expansion.patch mm-vma-make-brk-mappings-non-executable-under-mdwe.patch kfence-use-a-nofault-store-to-zero-the-guard-page.patch mm-filemap-update-the-folio-order-range-atomically.patch mm-userfaultfd-account-memory-allocated-for-unmap-events.patch mm-userfaultfd-drop-fork-context-reference-outside-event_wqhlock.patch mm-madvise-dont-declare-oom-for-madv_willneed-swapin.patch mm-mprotect-fix-unpaired-notifier-start-at-address-0.patch mm-hmm-refuse-secretmem-vmas-in-hmm_range_fault.patch mm-mglru-count-all-generations-as-evictable.patch mm-mglru-test-pg_lru-before-taking-a-folio-reference.patch mm-mglru-report-root-reclaim-to-memorypressure_level.patch hugetlbfs-recheck-the-vma-range-after-the-lock-wait.patch mm-hugetlb-dont-zap-non-present-entries-when-unmapping-a-folio.patch mm-hugetlb-unshare-pmds-of-a-split-vma-if-allocating-its-lock-fails.patch mm-hugetlb_cgroup-track-in-use-folios-per-cgroup.patch hugetlbfs-seal-shm_hugetlb-files-against-growth.patch mm-hugetlb-resolve-protnone-faults-without-a-uffd-bit.patch a.patch