Skip to contentSkip to conversation

userfaultfd: remove WRITE_ONCE when setting folio->index during UFFDIO_MOVE

PATCH Applied Suren Baghdasaryan 3 participants 3 messages Apr 15, 2024

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 userfaultfd: remove WRITE_ONCE when setting folio->index during UFFDIO_MOVE

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.

---
 mm/huge_memory.c | 2 +-
 mm/userfaultfd.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
mm/huge_memory.c +1 -1
index 58f2c4745d80..ee12726291f1 100644
@@ -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 */
mm/userfaultfd.c +1 -1
index b70618e8dcd2..575ccf90325a 100644
@@ -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

Signature · 1 line
2.44.0.683.g7961c838ac-goog
Reviewed-by on v1 1/1
#1 lore raw
Quoted 41 lines · Suren Baghdasaryan

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.

---
  mm/huge_memory.c | 2 +-
  mm/userfaultfd.c | 2 +-
  2 files changed, 2 insertions(+), 2 deletions(-)
mm/huge_memory.c +1 -1
index 58f2c4745d80..ee12726291f1 100644
@@ -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 */
mm/userfaultfd.c +1 -1
index b70618e8dcd2..575ccf90325a 100644
@@ -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 */
Quoted 1 line

base-commit: 3aec6b2b34e219898883d1e9ea7e911b4d3762a9

Signature · 3 lines
Cheers,

David / dhildenb
reviewer Reviewed-by on v1 1/1
#2 lore raw
In reply to Suren Baghdasaryan
Quoted 9 lines · Suren Baghdasaryan

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.

Signature · 1 line
Peter Xu