linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Suren Baghdasaryan <surenb@google.com>
To: David Hildenbrand <david@redhat.com>
Cc: Qi Zheng <zhengqi.arch@bytedance.com>,
	akpm@linux-foundation.org,  aarcange@redhat.com,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] mm: userfaultfd: fix unexpected change to src_folio when UFFDIO_MOVE fails
Date: Thu, 22 Feb 2024 13:41:22 -0800	[thread overview]
Message-ID: <CAJuCfpGznL_4PJXq6JfYTR6VZ7H=xbdQYNN_DzS1QR3OtRHGEQ@mail.gmail.com> (raw)
In-Reply-To: <ad82668d-10c6-4670-97f3-77c60a391c5f@redhat.com>

On Thu, Feb 22, 2024 at 12:43 AM David Hildenbrand <david@redhat.com> wrote:
>
> On 22.02.24 09:08, Qi Zheng wrote:
> > After ptep_clear_flush(), if we find that src_folio is pinned we will fail
> > UFFDIO_MOVE and put src_folio back to src_pte entry, but the change to
> > src_folio->{mapping,index} is not restored in this process. This is not
> > what we expected, so fix it.
> >
> > Fixes: adef440691ba ("userfaultfd: UFFDIO_MOVE uABI")
> > Signed-off-by: Qi Zheng <zhengqi.arch@bytedance.com>
> > ---
> >   mm/userfaultfd.c | 6 +++---
> >   1 file changed, 3 insertions(+), 3 deletions(-)
> >
> > diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c
> > index 4744d6a96f96..503ea77c81aa 100644
> > --- a/mm/userfaultfd.c
> > +++ b/mm/userfaultfd.c
> > @@ -1008,9 +1008,6 @@ static int move_present_pte(struct mm_struct *mm,
> >               goto out;
> >       }
> >
> > -     folio_move_anon_rmap(src_folio, dst_vma);
> > -     WRITE_ONCE(src_folio->index, linear_page_index(dst_vma, dst_addr));
> > -
> >       orig_src_pte = ptep_clear_flush(src_vma, src_addr, src_pte);
> >       /* Folio got pinned from under us. Put it back and fail the move. */
> >       if (folio_maybe_dma_pinned(src_folio)) {
> > @@ -1019,6 +1016,9 @@ static int move_present_pte(struct mm_struct *mm,
> >               goto out;
> >       }
> >
> > +     folio_move_anon_rmap(src_folio, dst_vma);
> > +     WRITE_ONCE(src_folio->index, linear_page_index(dst_vma, dst_addr));
> > +
> >       orig_dst_pte = mk_pte(&src_folio->page, dst_vma->vm_page_prot);
> >       /* Follow mremap() behavior and treat the entry dirty after the move */
> >       orig_dst_pte = pte_mkwrite(pte_mkdirty(orig_dst_pte), dst_vma);
>
> Indeed, LGTM.
>
> Reviewed-by: David Hildenbrand <david@redhat.com>

Thanks for catching this! Makes total sense to check before modification.

Reviewed-by: Suren Baghdasaryan <surenb@google.com>

>
> --
> Cheers,
>
> David / dhildenb
>


  reply	other threads:[~2024-02-22 21:41 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-22  8:08 Qi Zheng
2024-02-22  8:43 ` David Hildenbrand
2024-02-22 21:41   ` Suren Baghdasaryan [this message]
2024-02-22 21:00 ` Andrew Morton
2024-02-22 21:56   ` Suren Baghdasaryan
2024-02-28 10:46     ` David Hildenbrand

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAJuCfpGznL_4PJXq6JfYTR6VZ7H=xbdQYNN_DzS1QR3OtRHGEQ@mail.gmail.com' \
    --to=surenb@google.com \
    --cc=aarcange@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=david@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=zhengqi.arch@bytedance.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox