]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
mm: introduce vma->vm_flags modifier functions
authorSuren Baghdasaryan <surenb@google.com>
Wed, 26 Oct 2022 16:39:27 +0000 (16:39 +0000)
committerLiam R. Howlett <Liam.Howlett@oracle.com>
Wed, 4 Jan 2023 20:59:24 +0000 (15:59 -0500)
To keep vma locking correctness when vm_flags are modified, add modifier
functions to be used whenever flags are updated.

Signed-off-by: Suren Baghdasaryan <surenb@google.com>
include/linux/mm.h
include/linux/mm_types.h

index 8d5bb4e1b4e6a7c8218549c8d69f91552bad35b1..99cd1312534b1473a459e56c48f24151527dc4a9 100644 (file)
@@ -700,6 +700,44 @@ static inline void vma_init(struct vm_area_struct *vma, struct mm_struct *mm)
        vma_init_lock(vma);
 }
 
+/* Use when VMA is not part of the VMA tree and needs no locking */
+static inline
+void init_vm_flags(struct vm_area_struct *vma, unsigned long flags)
+{
+       WRITE_ONCE(vma->vm_flags, flags);
+}
+
+/* Use when VMA is part of the VMA tree and needs appropriate locking */
+static inline
+void reset_vm_flags(struct vm_area_struct *vma, unsigned long flags)
+{
+       vma_write_lock(vma);
+       init_vm_flags(vma, flags);
+}
+
+static inline
+void set_vm_flags(struct vm_area_struct *vma, unsigned long flags)
+{
+       vma_write_lock(vma);
+       vma->vm_flags |= flags;
+}
+
+static inline
+void clear_vm_flags(struct vm_area_struct *vma, unsigned long flags)
+{
+       vma_write_lock(vma);
+       vma->vm_flags &= ~flags;
+}
+
+static inline
+void mod_vm_flags(struct vm_area_struct *vma,
+                 unsigned long set, unsigned long clear)
+{
+       vma_write_lock(vma);
+       vma->vm_flags |= set;
+       vma->vm_flags &= ~clear;
+}
+
 static inline void vma_set_anonymous(struct vm_area_struct *vma)
 {
        vma->vm_ops = NULL;
index b73ea2a37d5c599c8a88c33a3298cb7b01f8f2e9..d6952df03afa0e78132aac89e22c76a5acb24d2e 100644 (file)
@@ -455,7 +455,12 @@ struct vm_area_struct {
 #endif
        };
 
-       unsigned long vm_flags;         /* Flags, see mm.h. */
+       /*
+        * Flags, see mm.h.
+        * WARNING! Do not modify directly to keep correct VMA locking.
+        * Use {init|reset|set|clear|mod}_vm_flags() functions instead.
+        */
+       unsigned long vm_flags;
 
        struct anon_vma *anon_vma;      /* Serialized by page_table_lock */