mm/memory: fix hugetlb_zap_begin() call in zap_vma_range_batched()
Subsystems (3)
PATCH 1/1 mm/memory: fix hugetlb_zap_begin() call in zap_vma_range_batched()
Commit f1fc44daf618 ("mm/hugetlb: don't lock private resv_map during final unmap") added zap_details parameter to hugetlb_zap_begin(). But the hugetlb_zap_begin() call in zap_vma_range_batched() is not updated. As a result, build fails as below. Fix it.
CC mm/memory.o.../mm/memory.c: In function ‘zap_vma_range_batched’:.../mm/memory.c:2308:9: error: too few arguments to function ‘hugetlb_zap_begin’
2308 | hugetlb_zap_begin(vma, &range.start, &range.end);
| ^~~~~~~~~~~~~~~~~
In file included from .../mm/memory.c:48:
.../include/linux/hugetlb.h:253:20: note: declared here
253 | static inline void hugetlb_zap_begin(struct vm_area_struct *vma,
| ^~~~~~~~~~~~~~~~~/* TODO: move below to commentary */
I didn't read the broken commit in depth. This fix is only build-tested. I wanted to report the issue with this as a temporal fix, but the broken commit doesn't have Link: tag. So directly posting this temporal and not very well verified fix first.
--- mm/memory.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/memory.c +1 -1
@@ -2305,7 +2305,7 @@ void zap_vma_range_batched(struct mmu_gather *tlb,mmu_notifier_range_init (&range,MMU_NOTIFY_CLEAR ,0 , vma->vm_mm, address, end); -hugetlb_zap_begin (vma, &range.start, &range.end); +hugetlb_zap_begin (vma, &range.start, &range.end, details);update_hiwater_rss (vma->vm_mm);mmu_notifier_invalidate_range_start (&range);/*
base-commit: 2d1388907095f676b59fe6dd22f244abc08408cf
Signature · 1 line
2.47.3
Quoted 2 lines · On Thu, 3 Sep 2026 17:00:26 -0700 SJ Park <[email protected]> wrote:
Commit
f1fc44daf618("mm/hugetlb: don't lock privateresv_mapduring final unmap")
FYI, this commit is in only mm-new.
Quoted 7 lines
added
zap_detailsparameter tohugetlb_zap_begin(). But
thehugetlb_zap_begin()call inzap_vma_range_batched()is not updated. As a result, build fails as below. Fix it.CC
mm/memory.o.../mm/memory.c: In function ‘zap_vma_range_batched’:.../mm/memory.c:2308:9: error: too few arguments to function ‘hugetlb_zap_begin’
Quoted 8 lines
2308 | hugetlb_zap_begin(vma, &range.start, &range.end); | ^~~~~~~~~~~~~~~~~ In file included from .../mm/memory.c:48: .../include/linux/hugetlb.h:253:20: note: declared here 253 | static inline void hugetlb_zap_begin(struct vm_area_struct *vma, | ^~~~~~~~~~~~~~~~~/* TODO: move below to commentary */
Oops, somehow my tool didn't process this... Sorry for noise.
Thanks,
SJ
[...]
Quoted 33 lines · On Thu, 3 Sep 2026 17:00:26 -0700 SJ Park <[email protected]> wrote:
Commit
f1fc44daf618("mm/hugetlb: don't lock privateresv_mapduring final unmap") addedzap_detailsparameter tohugetlb_zap_begin(). But thehugetlb_zap_begin()call inzap_vma_range_batched()is not updated. As a result, build fails as below. Fix it.CC
mm/memory.o.../mm/memory.c: In function ‘zap_vma_range_batched’:.../mm/memory.c:2308:9: error: too few arguments to function ‘hugetlb_zap_begin’2308 | hugetlb_zap_begin(vma, &range.start, &range.end); | ^~~~~~~~~~~~~~~~~ In file included from .../mm/memory.c:48: .../include/linux/hugetlb.h:253:20: note: declared here 253 | static inline void hugetlb_zap_begin(struct vm_area_struct *vma, | ^~~~~~~~~~~~~~~~~/* TODO: move below to commentary */
I didn't read the broken commit in depth. This fix is only build-tested. I wanted to report the issue with this as a temporal fix, but the broken commit doesn't have Link: tag. So directly posting this temporal and not very well verified fix first.
Fixes Fixes: f1fc44daf618 ("mm/hugetlb: don't lock private resv_map during final unmap")Signed-off-by SJ Park <[email protected]>--- mm/memory.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)mm/memory.c +0
-0
mm/memory.c void zap_vma_range_batched(struct mmu_gather *tlb, · line 2311
Quoted 8 lines
mm/memory.c +1
-1@@ -2305,7 +2305,7 @@ void zap_vma_range_batched(struct mmu_gather *tlb,mmu_notifier_range_init (&range,MMU_NOTIFY_CLEAR ,0 , vma->vm_mm, address, end); -hugetlb_zap_begin (vma, &range.start, &range.end); +hugetlb_zap_begin (vma, &range.start, &range.end, details);update_hiwater_rss (vma->vm_mm);mmu_notifier_invalidate_range_start (&range);/*
And this is not enough for some configs.
# /home/lkhack/linux/mm/memory.c: In function 'unmap_vmas':
# /home/lkhack/linux/mm/memory.c:2272:3: error: too many arguments to function 'hugetlb_zap_begin'
# 2272 | hugetlb_zap_begin(vma, &start, &end, &details); # | ^~~~~~~~~~~~~~~~~
# In file included from /home/lkhack/linux/mm/memory.c:48:
# /home/lkhack/linux/include/linux/hugetlb.h:322:20: note: declared here
# 322 | static inline void hugetlb_zap_begin(
Below change fixes the build on the config, too.
'''
include/linux/hugetlb.h +2 -1
@@ -321,7 +321,8 @@ static inline void adjust_range_if_pmd_sharing_possible(static inline void hugetlb_zap_begin (struct vm_area_struct *vma, -unsigned long *start,unsigned long *end) +unsigned long *start,unsigned long *end, +struct zap_details *details) { }
'''
So more complete version of the patch would look like below. Forgive me posting v2 as a reply for this case. I think this doesn't deserve a new thread.
Thanks,
SJ
=== >8 ===
From hackermail Thu Jan 1 00:00:00 1970
From: SJ Park <[email protected]>
Date: Thu, 3 Sep 2026 16:52:06 -0700
Subject: [PATCH v2] mm/memory: fix hugetlb_zap_begin() call in zap_vma_range_batched()
To: Andrew Morton <[email protected]>
Cc: "Liam R. Howlett" <[email protected]>
Cc: David Hildenbrand <[email protected]>
Cc: Lorenzo Stoakes <[email protected]>
Cc: Michal Hocko <[email protected]>
Cc: Mike Rapoport <[email protected]>
Cc: Muchun Song <[email protected]>
Cc: Oscar Salvador <[email protected]>
Cc: Suren Baghdasaryan <[email protected]>
Cc: Vlastimil Babka <[email protected]>
Cc: [email protected]
Cc: [email protected]
Commit f1fc44daf618 ("mm/hugetlb: don't lock private resv_map during final unmap") added zap_details parameter to hugetlb_zap_begin(). But the hugetlb_zap_begin() call in zap_vma_range_batched() is not updated. As a result, build fails as below.
CC mm/memory.o.../mm/memory.c: In function ‘zap_vma_range_batched’:.../mm/memory.c:2308:9: error: too few arguments to function ‘hugetlb_zap_begin’
2308 | hugetlb_zap_begin(vma, &range.start, &range.end);
| ^~~~~~~~~~~~~~~~~
In file included from .../mm/memory.c:48:
.../include/linux/hugetlb.h:253:20: note: declared here
253 | static inline void hugetlb_zap_begin(struct vm_area_struct *vma,
| ^~~~~~~~~~~~~~~~~It also fails on !CONFIG_HUGETLB_PAGE config.
.../mm/memory.c: In function 'unmap_vmas':
.../mm/memory.c:2272:3: error: too many arguments to function 'hugetlb_zap_begin'
2272 | hugetlb_zap_begin(vma, &start, &end, &details);
| ^~~~~~~~~~~~~~~~~
In file included from .../mm/memory.c:48:
.../include/linux/hugetlb.h:322:20: note: declared here
322 | static inline void hugetlb_zap_begin(---
I didn't read the broken commit in depth. This fix is only build-tested. I wanted to report the issue with this as a temporal fix, but the broken commit doesn't have Link: tag. So directly posting this temporal and not very well verified fix first.
Changes from v1
- v1: https://lore.kernel.org/[email protected]
- Fix !CONFIG_HUGETLB_PAGE build.
include/linux/hugetlb.h | 3 ++- mm/memory.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-)
include/linux/hugetlb.h +2 -1
@@ -321,7 +321,8 @@ static inline void adjust_range_if_pmd_sharing_possible(static inline void hugetlb_zap_begin (struct vm_area_struct *vma, -unsigned long *start,unsigned long *end) +unsigned long *start,unsigned long *end, +struct zap_details *details) { }
mm/memory.c +1 -1
@@ -2305,7 +2305,7 @@ void zap_vma_range_batched(struct mmu_gather *tlb,mmu_notifier_range_init (&range,MMU_NOTIFY_CLEAR ,0 , vma->vm_mm, address, end); -hugetlb_zap_begin (vma, &range.start, &range.end); +hugetlb_zap_begin (vma, &range.start, &range.end, details);update_hiwater_rss (vma->vm_mm);mmu_notifier_invalidate_range_start (&range);/*
base-commit: 2d1388907095f676b59fe6dd22f244abc08408cf
Signature · 1 line
2.47.3
Andrew Morton
maintainerQuoted 8 lines · On Thu, 3 Sep 2026 17:00:26 -0700 SJ Park <[email protected]> wrote:
Commit
f1fc44daf618("mm/hugetlb: don't lock privateresv_mapduring final unmap") addedzap_detailsparameter tohugetlb_zap_begin(). But thehugetlb_zap_begin()call inzap_vma_range_batched()is not updated. As a result, build fails as below. Fix it.CC
mm/memory.o.../mm/memory.c: In function ‘zap_vma_range_batched’:.../mm/memory.c:2308:9: error: too few arguments to function ‘hugetlb_zap_begin’
Quoted 6 lines
2308 | hugetlb_zap_begin(vma, &range.start, &range.end);
| ^~~~~~~~~~~~~~~~~
In file included from .../mm/memory.c:48:
.../include/linux/hugetlb.h:253:20: note: declared here
253 | static inline void hugetlb_zap_begin(struct vm_area_struct *vma,
| ^~~~~~~~~~~~~~~~~You cleverly pulled during the ten-minute-window after I'd pushed this out in order to pull it onto my build-test-machine.
There's probably a smarter way of doing this, not sure what though.
It doesn't happen often - I usually only need to push/pull the quilt patches (25-new).
Quoted 6 lines
/* TODO: move below to commentary */
I didn't read the broken commit in depth. This fix is only build-tested. I wanted to report the issue with this as a temporal fix, but the broken commit doesn't have Link: tag. So directly posting this temporal and not very well verified fix first.
Yeah, this is possible fix for
https://syzkaller.appspot.com/bug?extid=bd6aaf99e8443d8a9034 which I had chatgpt create for me. It's in limbo at present until I figure out what to do with it. Actually I'll hide it from others while figuring-out happens.
For the morbidly curious. It's really only a 2-line change, plus a bunch of changes to pass the zap_details down to __hugetlb_zap_begin().
From: Andrew Morton <[email protected]>
Subject: mm/hugetlb: don't lock private resv_map during final unmap
Replacing a private hugetlb mapping can trigger a lockdep circular locking warning and, if the corresponding reclaim, NBD and socket paths run concurrently, can deadlock userspace tasks.
The mmap path holds mmap_lock for write while removing an overlapping mapping and then reaches:
unmap_vmas()
hugetlb_zap_begin()
hugetlb_vma_lock_write()
resv_map->rw_semaThis establishes the lock ordering:
mmap_lock -> resv_map->rw_sema
Lockdep already knows about a transitive dependency in the other direction. In full, the relevant part of the dependency graph is:
resv_map->rw_sema
-> fs_reclaim
-> q->q_usage_counter
-> q->elevator_lock
-> set->srcu
-> cmd->lock
-> nsock->tx_lock
-> sk_lock-AF_INET6
-> mmap_lockThe resv_map->rw_sema -> fs_reclaim edge can be established by a private hugetlb fault. The fault holds the private VMA lock for read and huge_pte_alloc() can allocate page-table memory with reclaim enabled. The middle of the chain comes from the block and NBD paths, while sk_lock-AF_INET6 -> mmap_lock can be established when an IPv6 send copies from userspace while holding the socket lock and faults on the user buffer.
Consequently, lockdep summarizes the relevant reverse path as:
resv_map->rw_sema -> sk_lock-AF_INET6 -> mmap_lock
This is a transitive lockdep dependency, not a single call stack holding all three locks.
Commit bf4916922c60 ("hugetlbfs: extend hugetlb_vma_lock to private VMAs") made hugetlb_vma_lock_write() acquire resv_map->rw_sema for private hugetlb mappings. That lock is needed for partial zaps such as MADV_DONTNEED. It keeps a concurrent fault from running after the PTE has been cleared but before the hugepage has actually been returned to the pool, which could otherwise result in an unexpected SIGBUS when the hugepage pool is fully allocated.
That serialization is unnecessary when the VMA is being finally unmapped. mmap_lock prevents a concurrent fault from entering a VMA which is being removed, and private VMAs do not participate in hugetlb PMD sharing.
Pass the zap details to hugetlb_zap_begin() so that it can distinguish a final unmap. For final unmaps, continue taking the hugetlb VMA lock for shareable mappings, where it protects PMD sharing and the lifetime of the VMA lock, but do not take resv_map->rw_sema for a private mapping. Likewise, do not attempt to release the private reservation map lock from hugetlb_zap_end().
Non-final zaps continue taking resv_map->rw_sema, preserving the MADV_DONTNEED versus page-fault serialization for which private hugetlb VMA locking was introduced.
---
include/linux/hugetlb.h | 8 +++++--- mm/hugetlb.c | 16 ++++++++++++++-- mm/memory.c | 4 ++-- 3 files changed, 21 insertions(+), 7 deletions(-)
include/linux/hugetlb.h renamed from include/linux/hugetlb.h~mm-hugetlb-dont-lock-private-resv_map-during-final-unmap +5 -3
@@ -245,15 +245,17 @@ void adjust_range_if_pmd_sharing_possibl unsigned long *start, unsigned long *end);extern void __hugetlb_zap_begin (struct vm_area_struct *vma, -unsigned long *begin,unsigned long *end); +unsigned long *begin,unsigned long *end, +struct zap_details *details);extern void __hugetlb_zap_end (struct vm_area_struct *vma,struct zap_details *details);static inline void hugetlb_zap_begin (struct vm_area_struct *vma, -unsigned long *start,unsigned long *end) +unsigned long *start,unsigned long *end, +struct zap_details *details) {if (is_vm_hugetlb_page (vma)) -__hugetlb_zap_begin (vma, start, end); +__hugetlb_zap_begin (vma, start, end, details); } static inline void hugetlb_zap_end(struct vm_area_struct *vma,
mm/hugetlb.c renamed from mm/hugetlb.c~mm-hugetlb-dont-lock-private-resv_map-during-final-unmap +14 -2
@@ -5403,13 +5403,25 @@ void __unmap_hugepage_range(struct mmu_g }void __hugetlb_zap_begin (struct vm_area_struct *vma, -unsigned long *start,unsigned long *end) +unsigned long *start,unsigned long *end, +struct zap_details *details) { +zap_flags_t zap_flags = details ? details->zap_flags :0 ; +if (!vma->vm_file)/* hugetlbfs_file_mmap error */ return ;adjust_range_if_pmd_sharing_possible (vma, start, end); -hugetlb_vma_lock_write (vma); + +/* +* A final unmap cannot race with a fault in this VMA because +* mmap_lock prevents the fault from entering a VMA which is being +* removed. Skip the private resv_map lock in that case to avoid +* inverting its lock order with mmap_lock. Shareable mappings +* still need the VMA lock to protect PMD sharing. +*/ +if (!(zap_flags &ZAP_FLAG_UNMAP ) ||__vma_shareable_lock (vma)) +hugetlb_vma_lock_write (vma);if (vma->vm_file)i_mmap_lock_write (vma->vm_file->f_mapping); }
mm/memory.c renamed from mm/memory.c~mm-hugetlb-dont-lock-private-resv_map-during-final-unmap +2 -2
@@ -2268,7 +2268,7 @@ void unmap_vmas(struct mmu_gather *tlb,unsigned long start =max (vma->vm_start, unmap->vma_start);unsigned long end =min (vma->vm_end, unmap->vma_end); -hugetlb_zap_begin (vma, &start, &end); +hugetlb_zap_begin (vma, &start, &end, &details);__zap_vma_range (tlb, vma, start, end, &details);hugetlb_zap_end (vma, &details); vma =mas_find (unmap->mas, unmap->tree_end -1 );
@@ -2304,7 +2304,7 @@ void zap_vma_range_batched(struct mmu_gammu_notifier_range_init (&range,MMU_NOTIFY_CLEAR ,0 , vma->vm_mm, address, end); -hugetlb_zap_begin (vma, &range.start, &range.end); +hugetlb_zap_begin (vma, &range.start, &range.end, details);update_hiwater_rss (vma->vm_mm);mmu_notifier_invalidate_range_start (&range);/*
_
Quoted 17 lines · On Thu, 3 Sep 2026 17:35:40 -0700 Andrew Morton <[email protected]>…
Quoted 8 lines · On Thu, 3 Sep 2026 17:00:26 -0700 SJ Park <[email protected]> wrote:
Commit
f1fc44daf618("mm/hugetlb: don't lock privateresv_mapduring final unmap") addedzap_detailsparameter tohugetlb_zap_begin(). But thehugetlb_zap_begin()call inzap_vma_range_batched()is not updated. As a result, build fails as below. Fix it.CC
mm/memory.o.../mm/memory.c: In function ‘zap_vma_range_batched’:.../mm/memory.c:2308:9: error: too few arguments to function ‘hugetlb_zap_begin’Quoted 6 lines
2308 | hugetlb_zap_begin(vma, &range.start, &range.end); | ^~~~~~~~~~~~~~~~~ In file included from .../mm/memory.c:48: .../include/linux/hugetlb.h:253:20: note: declared here 253 | static inline void hugetlb_zap_begin(struct vm_area_struct *vma, | ^~~~~~~~~~~~~~~~~
Quoted 2 lines
You cleverly pulled during the ten-minute-window after I'd pushed this out in order to pull it onto my build-test-machine.
What a timing :)
I just found you pushed the tree again, after dropping the commit. I confirmed my build setup has no problem with it. Sorry for making this noise.
Quoted 5 lines
There's probably a smarter way of doing this, not sure what though.
It doesn't happen often - I usually only need to push/pull the quilt patches (25-new).
No worry, indeed I never had this situation before. And this was never a real issue for me.
Thanks,
SJ
[...]
Quoted 15 lines · Andrew Morton
Quoted 4 lines · On Thu, 3 Sep 2026 17:00:26 -0700 SJ Park <[email protected]> wrote:
I didn't read the broken commit in depth. This fix is only build-tested. I wanted to report the issue with this as a temporal fix, but the broken commit doesn't have Link: tag. So directly posting this temporal and not very well verified fix first.
Yeah, this is possible fix for
https://syzkaller.appspot.com/bug?extid=bd6aaf99e8443d8a9034 which I had chatgpt create for me. It's in limbo at present until I figure out what to do with it. Actually I'll hide it from others while figuring-out happens.
Quoted 7 lines
For the morbidly curious. It's really only a 2-line change, plus a bunch of changes to pass the
zap_detailsdown to__hugetlb_zap_begin().From: Andrew Morton <[email protected]>
Subject: mm/hugetlb: don't lock privateresv_mapduring final unmap
FYI this causes the following warn when running selftests:
------------[ cut here ]------------ DEBUG_RWSEMS_WARN_ON((rwsem_owner(sem) != current) && !rwsem_test_oflags(sem, RWSEM_NONSPINNABLE)): count = 0x0, magic = 0xffff8000059ff478, owner = 0x0, curr 0xffff800104a29000, list not empty WARNING: kernel/locking/rwsem.c:1412 at up_write+0x1f4/0x25c, CPU#6: pagemap_ioctl/1352 Modules linked in: rfkill fuse virtio_gpu drm_client_lib virtio_dma_buf drm_shmem_helper drm_kms_helper drm CPU: 6 UID: 0 PID: 1352 Comm: pagemap_ioctl Kdump: loaded Tainted: G N 7.3.0-rc1+ #70 PREEMPT Tainted: [N]=TEST Hardware name: QEMU QEMU Virtual Machine, BIOS edk2-stable202408-prebuilt.qemu.org 08/13/2024 pstate: 61400005 (nZCv daif +PAN -UAO -TCO +DIT -SSBS BTYPE=--) pc : up_write+0x1f4/0x25c lr : up_write+0x1f4/0x25c sp : ffffc0008903bab0 x29: ffffc0008903bab0 x28: ffff800104a29000 x27: 0000000000000000 x26: 0000000000000000 x25: 0000000000000000 x24: 0000000000000000 x23: ffff800104a29000 x22: ffffc000826254d0 x21: ffffc0008903bc68 x20: ffffc00081eb6000 x19: ffff8000059ff478 x18: 0000000000000020 x17: ffffc000800da3a8 x16: ffffc000800d971c x15: 00000000ffffffff x14: 0000000000000aab x13: ffffc00081edca98 x12: 0000000000002001 x11: ffffffffffe26460 x10: ffffc00081edca98 x9 : 0000000000000006 x8 : 0000000000000003 x7 : ffffc0008903b800 x6 : ffffc0008018bf04 x5 : ffff8001eeb7d208 x4 : ffff8001eeb7d280 x3 : 0000000000000001 x2 : 0000000000000000 x1 : 0000000000000000 x0 : ffff800104a29000 Call trace: up_write+0x1f4/0x25c (P) __hugetlb_zap_end+0x58/0xfc unmap_vmas+0xbc/0x178 exit_mmap+0xbc/0x4d0 __mmput+0x58/0x154 mmput+0x50/0x5c do_exit+0x2bc/0xd00 do_group_exit+0x34/0x90 pid_child_should_wake+0x0/0x5c invoke_syscall+0x54/0x110 el0_svc_common.constprop.0+0x40/0xe0 do_el0_svc+0x1c/0x28 el0_svc+0x54/0x424 el0t_64_sync_handler+0xa0/0xe4 el0t_64_sync+0x1b0/0x1b4 irq event stamp: 0 hardirqs last enabled at (0): [<0000000000000000>] 0x0 hardirqs last disabled at (0): [<ffffc000800ce3a8>] copy_process+0x8f8/0x2078 softirqs last enabled at (0): [<ffffc000800ce3b0>] copy_process+0x900/0x2078 softirqs last disabled at (0): [<0000000000000000>] 0x0 ---[ end trace 0000000000000000 ]---
Thanks,
Zenghui
Quoted 134 lines · Andrew Morton
Quoted 8 lines · On Thu, 3 Sep 2026 17:00:26 -0700 SJ Park <[email protected]> wrote:
Commit
f1fc44daf618("mm/hugetlb: don't lock privateresv_mapduring final unmap") addedzap_detailsparameter tohugetlb_zap_begin(). But thehugetlb_zap_begin()call inzap_vma_range_batched()is not updated. As a result, build fails as below. Fix it.CC
mm/memory.o.../mm/memory.c: In function ‘zap_vma_range_batched’:.../mm/memory.c:2308:9: error: too few arguments to function ‘hugetlb_zap_begin’Quoted 6 lines
2308 | hugetlb_zap_begin(vma, &range.start, &range.end); | ^~~~~~~~~~~~~~~~~ In file included from .../mm/memory.c:48: .../include/linux/hugetlb.h:253:20: note: declared here 253 | static inline void hugetlb_zap_begin(struct vm_area_struct *vma, | ^~~~~~~~~~~~~~~~~You cleverly pulled during the ten-minute-window after I'd pushed this out in order to pull it onto my build-test-machine.
There's probably a smarter way of doing this, not sure what though.
It doesn't happen often - I usually only need to push/pull the quilt patches (25-new).
Quoted 6 lines
/* TODO: move below to commentary */
I didn't read the broken commit in depth. This fix is only build-tested. I wanted to report the issue with this as a temporal fix, but the broken commit doesn't have Link: tag. So directly posting this temporal and not very well verified fix first.
Yeah, this is possible fix for
https://syzkaller.appspot.com/bug?extid=bd6aaf99e8443d8a9034 which I had chatgpt create for me. It's in limbo at present until I figure out what to do with it. Actually I'll hide it from others while figuring-out happens.For the morbidly curious. It's really only a 2-line change, plus a bunch of changes to pass the
zap_detailsdown to__hugetlb_zap_begin().From: Andrew Morton <[email protected]>
Subject: mm/hugetlb: don't lock privateresv_mapduring final unmapReplacing a private hugetlb mapping can trigger a lockdep circular locking warning and, if the corresponding reclaim, NBD and socket paths run concurrently, can deadlock userspace tasks.
The mmap path holds
mmap_lockfor write while removing an overlapping mapping and then reaches:
unmap_vmas()hugetlb_zap_begin() hugetlb_vma_lock_write() resv_map->rw_semaThis establishes the lock ordering:
mmap_lock->resv_map->rw_semaLockdep already knows about a transitive dependency in the other direction. In full, the relevant part of the dependency graph is:
resv_map->rw_sema-> fs_reclaim -> q->q_usage_counter -> q->elevator_lock -> set->srcu -> cmd->lock -> nsock->tx_lock -> sk_lock-AF_INET6 -> mmap_lockThe
resv_map->rw_sema->fs_reclaimedge can be established by a private hugetlb fault. The fault holds the private VMA lock for read andhuge_pte_alloc()can allocate page-table memory with reclaim enabled. The middle of the chain comes from the block and NBD paths, while sk_lock-AF_INET6 ->mmap_lockcan be established when an IPv6 send copies from userspace while holding the socket lock and faults on the user buffer.Consequently, lockdep summarizes the relevant reverse path as:
resv_map->rw_sema-> sk_lock-AF_INET6 ->mmap_lockThis is a transitive lockdep dependency, not a single call stack holding all three locks.
Commit
bf4916922c60("hugetlbfs: extendhugetlb_vma_lockto private VMAs") madehugetlb_vma_lock_write()acquireresv_map->rw_semafor private hugetlb mappings. That lock is needed for partial zaps such asMADV_DONTNEED. It keeps a concurrent fault from running after the PTE has been cleared but before the hugepage has actually been returned to the pool, which could otherwise result in an unexpected SIGBUS when the hugepage pool is fully allocated.That serialization is unnecessary when the VMA is being finally unmapped.
mmap_lockprevents a concurrent fault from entering a VMA which is being removed, and private VMAs do not participate in hugetlb PMD sharing.Pass the zap details to
hugetlb_zap_begin()so that it can distinguish a final unmap. For final unmaps, continue taking the hugetlb VMA lock for shareable mappings, where it protects PMD sharing and the lifetime of the VMA lock, but do not takeresv_map->rw_semafor a private mapping. Likewise, do not attempt to release the private reservation map lock fromhugetlb_zap_end().Non-final zaps continue taking
resv_map->rw_sema, preserving theMADV_DONTNEEDversus page-fault serialization for which private hugetlb VMA locking was introduced.Fixes bf4916922c60 ("hugetlbfs: extend hugetlb_vma_lock to private VMAs")Signed-off-by Andrew Morton <[email protected]>Reported-by [email protected]Cc Rik van Riel <[email protected]>Cc Muchun Song <[email protected]>Cc Oscar Salvador <[email protected]>Cc David Hildenbrand <[email protected]>Cc Liam R. Howlett <[email protected]>Cc Lorenzo Stoakes <[email protected]>Cc Michal Hocko <[email protected]>Cc Mike Rapoport <[email protected]>Cc Suren Baghdasaryan <[email protected]>Cc Vlastimil Babka <[email protected]>Cc Jane Chu <[email protected]>Assisted-by ChatGPT <[email protected]>Cc <[email protected]>Signed-off-by Andrew Morton <[email protected]>
Quoted 7 lines
---
include/linux/hugetlb.h | 8 +++++--- mm/hugetlb.c | 16 ++++++++++++++-- mm/memory.c | 4 ++-- 3 files changed, 21 insertions(+), 7 deletions(-)
hugetlb-madvise got stuck because of this. Reverting the patch fixed the issue.
From proc stack, it points to __hugetlb_zap_begin+0xf5/0x210, which corresponds to __hugetlb_zap_begin at mm/hugetlb.c:5436 in mm-new.
Signature · 2 lines
Best Regards, Yan, Zi
Andrew Morton
maintainerQuoted 10 lines · On Mon, 07 Sep 2026 20:14:45 -0400 "Zi Yan" <[email protected]> wrote:
Quoted 7 lines
---
include/linux/hugetlb.h | 8 +++++--- mm/hugetlb.c | 16 ++++++++++++++-- mm/memory.c | 4 ++-- 3 files changed, 21 insertions(+), 7 deletions(-)hugetlb-madvise got stuck because of this. Reverting the patch fixed the issue.
oops, thanks, that patch isn't supposed to be in mm.git.