* [PATCH 1/1] userfaultfd: remove WRITE_ONCE when setting folio->index during UFFDIO_MOVE
@ 2024-04-15 2:08 Suren Baghdasaryan
2024-04-15 7:37 ` David Hildenbrand
2024-04-15 13:31 ` Peter Xu
0 siblings, 2 replies; 3+ messages in thread
From: Suren Baghdasaryan @ 2024-04-15 2:08 UTC (permalink / raw)
To: akpm; +Cc: willy, david, peterx, lokeshgidra, linux-mm, linux-kernel, surenb
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.
Reported-by: Matthew Wilcox <willy@infradead.org>
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: Peter Xu <peterx@redhat.com>
Cc: Lokesh Gidra <lokeshgidra@google.com>
---
mm/huge_memory.c | 2 +-
mm/userfaultfd.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index 58f2c4745d80..ee12726291f1 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -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 */
diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c
index b70618e8dcd2..575ccf90325a 100644
--- a/mm/userfaultfd.c
+++ b/mm/userfaultfd.c
@@ -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 */
base-commit: 3aec6b2b34e219898883d1e9ea7e911b4d3762a9
--
2.44.0.683.g7961c838ac-goog
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 1/1] userfaultfd: remove WRITE_ONCE when setting folio->index during UFFDIO_MOVE
2024-04-15 2:08 [PATCH 1/1] userfaultfd: remove WRITE_ONCE when setting folio->index during UFFDIO_MOVE Suren Baghdasaryan
@ 2024-04-15 7:37 ` David Hildenbrand
2024-04-15 13:31 ` Peter Xu
1 sibling, 0 replies; 3+ messages in thread
From: David Hildenbrand @ 2024-04-15 7:37 UTC (permalink / raw)
To: Suren Baghdasaryan, akpm
Cc: willy, peterx, lokeshgidra, linux-mm, linux-kernel
On 15.04.24 04:08, Suren Baghdasaryan wrote:
> 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.
>
> Reported-by: Matthew Wilcox <willy@infradead.org>
> Signed-off-by: Suren Baghdasaryan <surenb@google.com>
> Cc: David Hildenbrand <david@redhat.com>
> Cc: Peter Xu <peterx@redhat.com>
> Cc: Lokesh Gidra <lokeshgidra@google.com>
> ---
> mm/huge_memory.c | 2 +-
> mm/userfaultfd.c | 2 +-
> 2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/mm/huge_memory.c b/mm/huge_memory.c
> index 58f2c4745d80..ee12726291f1 100644
> --- a/mm/huge_memory.c
> +++ b/mm/huge_memory.c
> @@ -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 */
> diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c
> index b70618e8dcd2..575ccf90325a 100644
> --- a/mm/userfaultfd.c
> +++ b/mm/userfaultfd.c
> @@ -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 */
>
> base-commit: 3aec6b2b34e219898883d1e9ea7e911b4d3762a9
Reviewed-by: David Hildenbrand <david@redhat.com>
--
Cheers,
David / dhildenb
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 1/1] userfaultfd: remove WRITE_ONCE when setting folio->index during UFFDIO_MOVE
2024-04-15 2:08 [PATCH 1/1] userfaultfd: remove WRITE_ONCE when setting folio->index during UFFDIO_MOVE Suren Baghdasaryan
2024-04-15 7:37 ` David Hildenbrand
@ 2024-04-15 13:31 ` Peter Xu
1 sibling, 0 replies; 3+ messages in thread
From: Peter Xu @ 2024-04-15 13:31 UTC (permalink / raw)
To: Suren Baghdasaryan
Cc: akpm, willy, david, lokeshgidra, linux-mm, linux-kernel
On Sun, Apr 14, 2024 at 07:08:21PM -0700, Suren Baghdasaryan wrote:
> 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.
>
> Reported-by: Matthew Wilcox <willy@infradead.org>
> Signed-off-by: Suren Baghdasaryan <surenb@google.com>
> Cc: David Hildenbrand <david@redhat.com>
> Cc: Peter Xu <peterx@redhat.com>
> Cc: Lokesh Gidra <lokeshgidra@google.com>
Reviewed-by: Peter Xu <peterx@redhat.com>
--
Peter Xu
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-04-15 13:31 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-15 2:08 [PATCH 1/1] userfaultfd: remove WRITE_ONCE when setting folio->index during UFFDIO_MOVE Suren Baghdasaryan
2024-04-15 7:37 ` David Hildenbrand
2024-04-15 13:31 ` Peter Xu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox