Re: [PATCH] mm/madvise: handle madvise_lock() failure during race unwinding
From: Barry Song
Date: Mon Jun 02 2025 - 17:31:10 EST
On Tue, Jun 3, 2025 at 5:49 AM SeongJae Park <sj@xxxxxxxxxx> wrote:
>
> 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>
LGTM, thanks!
Reviewed-by: Barry Song <baohua@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