Skip to contentSkip to conversation

mm: introduce vm_flags_reset_once to replace WRITE_ONCE vm_flags updates

PATCH Applied Suren Baghdasaryan 3 participants 3 messages Feb 1, 2023 – Feb 8, 2023

Subsystems (3)
lore
Share & tools
lore

Suren Baghdasaryan

author reviewer
#0 lore raw

PATCH 1/1 mm: introduce vm_flags_reset_once to replace WRITE_ONCE vm_flags updates

Provide vm_flags_reset_once() and replace the vm_flags updates which used WRITE_ONCE() to prevent compiler optimizations.

Fixes 0cce31a0aa0e ("mm: replace vma->vm_flags direct modifications with modifier calls")

---
Notes:
- The patch applies cleanly over mm-unstable
- The SHA in Fixes: line is from mm-unstable, so is... unstable

 include/linux/mm.h | 7 +++++++
 mm/mlock.c         | 4 ++--
 2 files changed, 9 insertions(+), 2 deletions(-)
include/linux/mm.h +7 -0
index 5bf0ad48faaa..23ce04f6e91e 100644
@@ -648,6 +648,13 @@ static inline void vm_flags_reset(struct vm_area_struct *vma,
 	vm_flags_init(vma, flags);
 }
 
+static inline void vm_flags_reset_once(struct vm_area_struct *vma,
+				       vm_flags_t flags)
+{
+	mmap_assert_write_locked(vma->vm_mm);
+	WRITE_ONCE(ACCESS_PRIVATE(vma, __vm_flags), flags);
+}
+
 static inline void vm_flags_set(struct vm_area_struct *vma,
 				vm_flags_t flags)
 {
mm/mlock.c +2 -2
index ed49459e343e..617469fce96d 100644
@@ -380,7 +380,7 @@ static void mlock_vma_pages_range(struct vm_area_struct *vma,
 	 */
 	if (newflags & VM_LOCKED)
 		newflags |= VM_IO;
-	vm_flags_reset(vma, newflags);
+	vm_flags_reset_once(vma, newflags);
 
 	lru_add_drain();
 	walk_page_range(vma->vm_mm, start, end, &mlock_walk_ops, NULL);
@@ -388,7 +388,7 @@ static void mlock_vma_pages_range(struct vm_area_struct *vma,
 
 	if (newflags & VM_IO) {
 		newflags &= ~VM_IO;
-		vm_flags_reset(vma, newflags);
+		vm_flags_reset_once(vma, newflags);
 	}
 }
 
Signature · 1 line
2.39.1.456.gfc5497dd1b-goog
reviewer Acked-by on v1 1/1
#1 lore raw
Quoted 6 lines · Suren Baghdasaryan

Provide vm_flags_reset_once() and replace the vm_flags updates which used WRITE_ONCE() to prevent compiler optimizations.

Fixes 0cce31a0aa0e ("mm: replace vma->vm_flags direct modifications with modifier calls")

This would have been better folded into the vm_flags modification patch because it would be more obvious change. Hugh has provided a very nice comment in mlock_vma_pages_range but the git blame would be more visible when the conversion is from WRITE_ONCE.

One way or the other

Quoted 51 lines

---
Notes:
- The patch applies cleanly over mm-unstable
- The SHA in Fixes: line is from mm-unstable, so is... unstable

 include/linux/mm.h | 7 +++++++
 mm/mlock.c         | 4 ++--
 2 files changed, 9 insertions(+), 2 deletions(-)
include/linux/mm.h +7 -0
index 5bf0ad48faaa..23ce04f6e91e 100644
@@ -648,6 +648,13 @@ static inline void vm_flags_reset(struct vm_area_struct *vma,
 	vm_flags_init(vma, flags);
 }
 
+static inline void vm_flags_reset_once(struct vm_area_struct *vma,
+				       vm_flags_t flags)
+{
+	mmap_assert_write_locked(vma->vm_mm);
+	WRITE_ONCE(ACCESS_PRIVATE(vma, __vm_flags), flags);
+}
+
 static inline void vm_flags_set(struct vm_area_struct *vma,
 				vm_flags_t flags)
 {
mm/mlock.c +2 -2
index ed49459e343e..617469fce96d 100644
@@ -380,7 +380,7 @@ static void mlock_vma_pages_range(struct vm_area_struct *vma,
 	 */
 	if (newflags & VM_LOCKED)
 		newflags |= VM_IO;
-	vm_flags_reset(vma, newflags);
+	vm_flags_reset_once(vma, newflags);
 
 	lru_add_drain();
 	walk_page_range(vma->vm_mm, start, end, &mlock_walk_ops, NULL);
@@ -388,7 +388,7 @@ static void mlock_vma_pages_range(struct vm_area_struct *vma,
 
 	if (newflags & VM_IO) {
 		newflags &= ~VM_IO;
-		vm_flags_reset(vma, newflags);
+		vm_flags_reset_once(vma, newflags);
 	}
 }
 
Signature · 1 line
2.39.1.456.gfc5497dd1b-goog
Signature · 2 lines
Michal Hocko
SUSE Labs
Reviewed-by on v1 1/1
#2 lore raw
In reply to Suren Baghdasaryan
Quoted 47 lines · Suren Baghdasaryan

Provide vm_flags_reset_once() and replace the vm_flags updates which used WRITE_ONCE() to prevent compiler optimizations.

Fixes 0cce31a0aa0e ("mm: replace vma->vm_flags direct modifications with modifier calls")

---
Notes:
- The patch applies cleanly over mm-unstable
- The SHA in Fixes: line is from mm-unstable, so is... unstable

 include/linux/mm.h | 7 +++++++
 mm/mlock.c         | 4 ++--
 2 files changed, 9 insertions(+), 2 deletions(-)
include/linux/mm.h +7 -0
index 5bf0ad48faaa..23ce04f6e91e 100644
@@ -648,6 +648,13 @@ static inline void vm_flags_reset(struct vm_area_struct *vma,
 	vm_flags_init(vma, flags);
 }
 
+static inline void vm_flags_reset_once(struct vm_area_struct *vma,
+				       vm_flags_t flags)
+{
+	mmap_assert_write_locked(vma->vm_mm);
+	WRITE_ONCE(ACCESS_PRIVATE(vma, __vm_flags), flags);
+}
+
 static inline void vm_flags_set(struct vm_area_struct *vma,
 				vm_flags_t flags)
 {
mm/mlock.c +1 -1
index ed49459e343e..617469fce96d 100644
@@ -380,7 +380,7 @@ static void mlock_vma_pages_range(struct vm_area_struct *vma,
 	 */
 	if (newflags & VM_LOCKED)
 		newflags |= VM_IO;
-	vm_flags_reset(vma, newflags);
+	vm_flags_reset_once(vma, newflags);
 
 	lru_add_drain();
 	walk_page_range(vma->vm_mm, start, end, &mlock_walk_ops, NULL);

mm/mlock.c static void mlock_vma_pages_range(struct vm_area_struct *vma, · line 393

Quoted 7 lines
mm/mlock.c +1 -1
@@ -388,7 +388,7 @@ static void mlock_vma_pages_range(struct vm_area_struct *vma,
 
 	if (newflags & VM_IO) {
 		newflags &= ~VM_IO;
-		vm_flags_reset(vma, newflags);
+		vm_flags_reset_once(vma, newflags);
 	}
 }
Quoted 4 lines
Signature · 2 lines
-- 
2.39.1.456.gfc5497dd1b-goog