userfaultfd: remove WRITE_ONCE when setting folio->index during UFFDIO_MOVE
authorSuren Baghdasaryan <surenb@google.com>
Mon, 15 Apr 2024 02:08:21 +0000 (19:08 -0700)
committerAndrew Morton <akpm@linux-foundation.org>
Mon, 6 May 2024 00:53:37 +0000 (17:53 -0700)
When folio is moved with UFFDIO_MOVE it gets locked before the rmap and
index are modified.  Due to the folio lock being already held,
WRITE_ONCE() is not needed when setting the folio index.  Remove it.

Link: https://lkml.kernel.org/r/20240415020821.1152951-1-surenb@google.com
Reported-by: Matthew Wilcox <willy@infradead.org>
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
Reviewed-by: David Hildenbrand <david@redhat.com>
Reviewed-by: Peter Xu <peterx@redhat.com>
Cc: Lokesh Gidra <lokeshgidra@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/huge_memory.c
mm/userfaultfd.c

index 264e09043f09695a0a8aef043ba2aa2721c99f38..31b6bbffea5216135b9381aeb50ea319540ec983 100644 (file)
@@ -2200,7 +2200,7 @@ int move_pages_huge_pmd(struct mm_struct *mm, pmd_t *dst_pmd, pmd_t *src_pmd, pm
                }
 
                folio_move_anon_rmap(src_folio, dst_vma);
-               WRITE_ONCE(src_folio->index, linear_page_index(dst_vma, dst_addr));
+               src_folio->index = linear_page_index(dst_vma, dst_addr);
 
                _dst_pmd = mk_huge_pmd(&src_folio->page, dst_vma->vm_page_prot);
                /* Follow mremap() behavior and treat the entry dirty after the move */
index b70618e8dcd2486821303fa9ae6360baa40fbb62..575ccf90325aa7740b11246455cbdc98ac67a61c 100644 (file)
@@ -1026,7 +1026,7 @@ static int move_present_pte(struct mm_struct *mm,
        }
 
        folio_move_anon_rmap(src_folio, dst_vma);
-       WRITE_ONCE(src_folio->index, linear_page_index(dst_vma, dst_addr));
+       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 */