]> Git Repo - linux.git/commitdiff
mm: introduce vma->vm_flags wrapper functions
authorSuren Baghdasaryan <[email protected]>
Thu, 26 Jan 2023 19:37:47 +0000 (11:37 -0800)
committerAndrew Morton <[email protected]>
Fri, 10 Feb 2023 00:51:39 +0000 (16:51 -0800)
vm_flags are among VMA attributes which affect decisions like VMA merging
and splitting.  Therefore all vm_flags modifications are performed after
taking exclusive mmap_lock to prevent vm_flags updates racing with such
operations.  Introduce modifier functions for vm_flags to be used whenever
flags are updated.  This way we can better check and control correct
locking behavior during these updates.

Link: https://lkml.kernel.org/r/[email protected]
Signed-off-by: Suren Baghdasaryan <[email protected]>
Reviewed-by: Davidlohr Bueso <[email protected]>
Acked-by: Michal Hocko <[email protected]>
Acked-by: Mel Gorman <[email protected]>
Acked-by: Mike Rapoport (IBM) <[email protected]>
Reviewed-by: Hyeonggon Yoo <[email protected]>
Cc: Andy Lutomirski <[email protected]>
Cc: Arjun Roy <[email protected]>
Cc: Axel Rasmussen <[email protected]>
Cc: David Hildenbrand <[email protected]>
Cc: David Howells <[email protected]>
Cc: David Rientjes <[email protected]>
Cc: Eric Dumazet <[email protected]>
Cc: Greg Thelen <[email protected]>
Cc: Hugh Dickins <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Jann Horn <[email protected]>
Cc: Joel Fernandes <[email protected]>
Cc: Johannes Weiner <[email protected]>
Cc: Kent Overstreet <[email protected]>
Cc: Laurent Dufour <[email protected]>
Cc: Liam R. Howlett <[email protected]>
Cc: Lorenzo Stoakes <[email protected]>
Cc: Matthew Wilcox <[email protected]>
Cc: Minchan Kim <[email protected]>
Cc: Paul E. McKenney <[email protected]>
Cc: Peter Oskolkov <[email protected]>
Cc: Peter Xu <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Punit Agrawal <[email protected]>
Cc: Sebastian Andrzej Siewior <[email protected]>
Cc: Sebastian Reichel <[email protected]>
Cc: Shakeel Butt <[email protected]>
Cc: Soheil Hassas Yeganeh <[email protected]>
Cc: Song Liu <[email protected]>
Cc: Vlastimil Babka <[email protected]>
Cc: Will Deacon <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
include/linux/mm.h
include/linux/mm_types.h

index dcc34533d2f6f3708e456fb5a2727b77f182b026..e2df5d122b67fdd7b6d77c846a2a126f989fa478 100644 (file)
@@ -627,6 +627,46 @@ static inline void vma_init(struct vm_area_struct *vma, struct mm_struct *mm)
        INIT_LIST_HEAD(&vma->anon_vma_chain);
 }
 
+/* Use when VMA is not part of the VMA tree and needs no locking */
+static inline void vm_flags_init(struct vm_area_struct *vma,
+                                vm_flags_t flags)
+{
+       ACCESS_PRIVATE(vma, __vm_flags) = flags;
+}
+
+/* Use when VMA is part of the VMA tree and modifications need coordination */
+static inline void vm_flags_reset(struct vm_area_struct *vma,
+                                 vm_flags_t flags)
+{
+       mmap_assert_write_locked(vma->vm_mm);
+       vm_flags_init(vma, flags);
+}
+
+static inline void vm_flags_set(struct vm_area_struct *vma,
+                               vm_flags_t flags)
+{
+       mmap_assert_write_locked(vma->vm_mm);
+       ACCESS_PRIVATE(vma, __vm_flags) |= flags;
+}
+
+static inline void vm_flags_clear(struct vm_area_struct *vma,
+                                 vm_flags_t flags)
+{
+       mmap_assert_write_locked(vma->vm_mm);
+       ACCESS_PRIVATE(vma, __vm_flags) &= ~flags;
+}
+
+/*
+ * Use only when the order of set/clear operations is unimportant, otherwise
+ * use vm_flags_{set|clear} explicitly.
+ */
+static inline void vm_flags_mod(struct vm_area_struct *vma,
+                               vm_flags_t set, vm_flags_t clear)
+{
+       mmap_assert_write_locked(vma->vm_mm);
+       vm_flags_init(vma, (vma->vm_flags | set) & ~clear);
+}
+
 static inline void vma_set_anonymous(struct vm_area_struct *vma)
 {
        vma->vm_ops = NULL;
index 5ca11c6c46e8d3599cb9f64dca1c161cff8df779..10a1e41f4e701cdaf595c440a873f8132a655dae 100644 (file)
@@ -491,7 +491,15 @@ struct vm_area_struct {
         * See vmf_insert_mixed_prot() for discussion.
         */
        pgprot_t vm_page_prot;
-       unsigned long vm_flags;         /* Flags, see mm.h. */
+
+       /*
+        * Flags, see mm.h.
+        * To modify use vm_flags_{init|reset|set|clear|mod} functions.
+        */
+       union {
+               const vm_flags_t vm_flags;
+               vm_flags_t __private __vm_flags;
+       };
 
        /*
         * For areas with an address space and backing store,
This page took 0.057912 seconds and 4 git commands to generate.