[PATCH] mm/madvise: handle madvise_lock() failure during race unwinding

From: SeongJae Park
Date: Mon Jun 02 2025 - 13:49:45 EST


When unwinding race on -ERESTARTNOINTR handling of process_madvise(),
madvise_lock() failure is ignored. Check the failure and abort
remaining works in the case.

Fixes: 4000e3d0a367 ("mm/madvise: remove redundant mmap_lock operations from process_madvise()")
Cc: stable@xxxxxxxxxx
Reported-by: Barry Song <21cnbao@xxxxxxxxx>
Closes: https://lore.kernel.org/CAGsJ_4xJXXO0G+4BizhohSZ4yDteziPw43_uF8nPXPWxUVChzw@xxxxxxxxxxxxxx
Signed-off-by: SeongJae Park <sj@xxxxxxxxxx>
---
mm/madvise.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/mm/madvise.c b/mm/madvise.c
index 8433ac9b27e0..5f7a66a1617e 100644
--- a/mm/madvise.c
+++ b/mm/madvise.c
@@ -1881,7 +1881,9 @@ static ssize_t vector_madvise(struct mm_struct *mm, struct iov_iter *iter,
/* Drop and reacquire lock to unwind race. */
madvise_finish_tlb(&madv_behavior);
madvise_unlock(mm, behavior);
- madvise_lock(mm, behavior);
+ ret = madvise_lock(mm, behavior);
+ if (ret)
+ goto out;
madvise_init_tlb(&madv_behavior, mm);
continue;
}
@@ -1892,6 +1894,7 @@ static ssize_t vector_madvise(struct mm_struct *mm, struct iov_iter *iter,
madvise_finish_tlb(&madv_behavior);
madvise_unlock(mm, behavior);

+out:
ret = (total_len - iov_iter_count(iter)) ? : ret;

return ret;

base-commit: d85ea9175e4147e15ff6e3c0e02c6c447ef473c8
--
2.39.5