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

Suren Baghdasaryan
2025-01-07T17:31:40Z

On Tue, Jan 7, 2025 at 9:28 AM Vlastimil Babka <vbabka@suse.cz> wrote:
>
> 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?)

I checked with Lokesh who added that uffd code and he confirmed that
uffd will handle errors correctly.

>
> > @@ -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

Ack.

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