linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm/madvise: handle madvise_lock() failure during race unwinding
@ 2025-06-02 17:49 SeongJae Park
  2025-06-02 19:20 ` Jann Horn
                   ` (4 more replies)
  0 siblings, 5 replies; 9+ messages in thread
From: SeongJae Park @ 2025-06-02 17:49 UTC (permalink / raw)
  To: Andrew Morton
  Cc: SeongJae Park, Liam R. Howlett, David Hildenbrand, Jann Horn,
	Lorenzo Stoakes, Shakeel Butt, Vlastimil Babka, linux-kernel,
	linux-mm, stable, Barry Song

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@kernel.org
Reported-by: Barry Song <21cnbao@gmail.com>
Closes: https://lore.kernel.org/CAGsJ_4xJXXO0G+4BizhohSZ4yDteziPw43_uF8nPXPWxUVChzw@mail.gmail.com
Signed-off-by: SeongJae Park <sj@kernel.org>
---
 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


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2025-06-02 21:31 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-06-02 17:49 [PATCH] mm/madvise: handle madvise_lock() failure during race unwinding SeongJae Park
2025-06-02 19:20 ` Jann Horn
2025-06-02 19:28   ` Lorenzo Stoakes
2025-06-02 19:34     ` Jann Horn
2025-06-02 19:37       ` Lorenzo Stoakes
2025-06-02 19:38 ` Lorenzo Stoakes
2025-06-02 19:58 ` David Hildenbrand
2025-06-02 20:22 ` Shakeel Butt
2025-06-02 21:30 ` Barry Song

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox