[PATCH] mm/khugepaged: fix issue with tracking lock
From: Lorenzo Stoakes (Oracle)
Date: Tue Mar 31 2026 - 08:11:18 EST
We are incorrectly treating lock_dropped to track both whether the lock is
currently held and whether or not the lock was ever dropped.
Update this change to account for this.
Signed-off-by: Lorenzo Stoakes (Oracle) <ljs@xxxxxxxxxx>
---
mm/khugepaged.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/mm/khugepaged.c b/mm/khugepaged.c
index d21348b85a59..b8452dbdb043 100644
--- a/mm/khugepaged.c
+++ b/mm/khugepaged.c
@@ -2828,6 +2828,7 @@ int madvise_collapse(struct vm_area_struct *vma, unsigned long start,
unsigned long hstart, hend, addr;
enum scan_result last_fail = SCAN_FAIL;
int thps = 0;
+ bool mmap_unlocked = false;
BUG_ON(vma->vm_start > start);
BUG_ON(vma->vm_end < end);
@@ -2850,10 +2851,11 @@ int madvise_collapse(struct vm_area_struct *vma, unsigned long start,
for (addr = hstart; addr < hend; addr += HPAGE_PMD_SIZE) {
enum scan_result result = SCAN_FAIL;
- if (*lock_dropped) {
+ if (mmap_unlocked) {
cond_resched();
mmap_read_lock(mm);
- *lock_dropped = false;
+ mmap_unlocked = false;
+ *lock_dropped = true;
result = hugepage_vma_revalidate(mm, addr, false, &vma,
cc);
if (result != SCAN_SUCCEED) {
@@ -2864,7 +2866,7 @@ int madvise_collapse(struct vm_area_struct *vma, unsigned long start,
hend = min(hend, vma->vm_end & HPAGE_PMD_MASK);
}
- result = collapse_single_pmd(addr, vma, lock_dropped, cc);
+ result = collapse_single_pmd(addr, vma, &mmap_unlocked, cc);
switch (result) {
case SCAN_SUCCEED:
@@ -2893,8 +2895,10 @@ int madvise_collapse(struct vm_area_struct *vma, unsigned long start,
out_maybelock:
/* Caller expects us to hold mmap_lock on return */
- if (*lock_dropped)
+ if (mmap_unlocked) {
+ *lock_dropped = true;
mmap_read_lock(mm);
+ }
out_nolock:
mmap_assert_locked(mm);
mmdrop(mm);
--
2.53.0