Re: [PATCH v7 08/17] mm: allow vma_start_read_locked/vma_start_read_locked_nested to fail

Vlastimil Babka
2025-01-07T17:28:39Z

On 12/26/24 18:07, Suren Baghdasaryan wrote:
> With upcoming replacement of vm_lock with vm_refcnt, we need to handle a
> possibility of vma_start_read_locked/vma_start_read_locked_nested failing
> due to refcount overflow. Prepare for such possibility by changing these
> APIs and adjusting their users.
>
> Signed-off-by: Suren Baghdasaryan <surenb@google.com>
> Cc: Lokesh Gidra <lokeshgidra@google.com>

Acked-by: Vlastimil Babka <vbabka@suse.cz>

(I don't know if this can break some uffd users?)

> @@ -1483,10 +1484,16 @@ static int uffd_move_lock(struct mm_struct *mm,
> mmap_read_lock(mm);
> err = find_vmas_mm_locked(mm, dst_start, src_start, dst_vmap, src_vmap);
> if (!err) {
> - vma_start_read_locked(*dst_vmap);
> - if (*dst_vmap != *src_vmap)
> - vma_start_read_locked_nested(*src_vmap,
> - SINGLE_DEPTH_NESTING);
> + if (vma_start_read_locked(*dst_vmap)) {
> + if (*dst_vmap != *src_vmap) {
> + if (!vma_start_read_locked_nested(*src_vmap,
> + SINGLE_DEPTH_NESTING)) {
> + vma_end_read(*dst_vmap);
> + err = -EAGAIN;
> + }
> + }
> + } else
> + err = -EAGAIN;

Nit: { } per style

> }
> mmap_read_unlock(mm);
> return err;