]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
kernel/fork: assert no VMA readers during its destruction
authorSuren Baghdasaryan <surenb@google.com>
Thu, 7 Jul 2022 23:24:22 +0000 (16:24 -0700)
committerLiam R. Howlett <Liam.Howlett@oracle.com>
Wed, 4 Jan 2023 20:59:26 +0000 (15:59 -0500)
Assert there are no holders of VMA lock for reading when it is about to be
destroyed.

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

index ecb1cd991443db21e1afbedca60474adcc49591f..3851f786c95aff13094cda771acf99b25d47f53a 100644 (file)
@@ -677,6 +677,13 @@ static inline void vma_assert_write_locked(struct vm_area_struct *vma)
        VM_BUG_ON_VMA(vma->vm_lock_seq != READ_ONCE(vma->vm_mm->mm_lock_seq), vma);
 }
 
+static inline void vma_assert_no_reader(struct vm_area_struct *vma)
+{
+       VM_BUG_ON_VMA(rwsem_is_locked(&vma->lock) &&
+                     vma->vm_lock_seq != READ_ONCE(vma->vm_mm->mm_lock_seq),
+                     vma);
+}
+
 #else /* CONFIG_PER_VMA_LOCK */
 
 static inline void vma_init_lock(struct vm_area_struct *vma) {}
@@ -686,6 +693,7 @@ static inline bool vma_read_trylock(struct vm_area_struct *vma)
 static inline void vma_read_unlock(struct vm_area_struct *vma) {}
 static inline void vma_assert_locked(struct vm_area_struct *vma) {}
 static inline void vma_assert_write_locked(struct vm_area_struct *vma) {}
+static inline void vma_assert_no_reader(struct vm_area_struct *vma) {}
 
 #endif /* CONFIG_PER_VMA_LOCK */
 
index a3e06c2e5432c338d58257134baacc95426ec526..b3a7ffc2c0a4a9b4fb8ab2197ca4e51faf9aa3c0 100644 (file)
@@ -485,6 +485,8 @@ static void __vm_area_free(struct rcu_head *head)
 {
        struct vm_area_struct *vma = container_of(head, struct vm_area_struct,
                                                  vm_rcu);
+       /* The vma should either have no lock holders or be write-locked. */
+       vma_assert_no_reader(vma);
        kmem_cache_free(vm_area_cachep, vma);
 }
 #endif