]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
there are issues here
authorLiam R. Howlett <Liam.Howlett@oracle.com>
Tue, 8 Apr 2025 19:37:27 +0000 (15:37 -0400)
committerLiam R. Howlett <Liam.Howlett@oracle.com>
Tue, 8 Apr 2025 20:02:32 +0000 (16:02 -0400)
Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com>
arch/x86/kernel/tboot.c
drivers/firmware/efi/efi.c
include/linux/mm.h
include/linux/mm_types.h
kernel/fork.c
mm/init-mm.c
mm/mmap.c
mm/vma.c
mm/vma.h

index 46b8f1f16676e4e1c0c59fad5030f04cead5dd3d..164aa0050b6e70343cbccdf21a3474220c090060 100644 (file)
@@ -95,7 +95,7 @@ void __init tboot_probe(void)
 
 static pgd_t *tboot_pg_dir;
 static struct mm_struct tboot_mm = {
-       .mm_mt          = MTREE_INIT_EXT(mm_mt, MM_MT_FLAGS, tboot_mm.mmap_lock),
+       .mm_mt          = MTREE_INIT(mm_mt, MM_MT_FLAGS),
        .pgd            = swapper_pg_dir,
        .mm_users       = ATOMIC_INIT(2),
        .mm_count       = ATOMIC_INIT(1),
index 7309394b8fc98cf7a3424af209b752f0251c8c89..c70554a3a54e20d2c013a535f1896bc9723e7df4 100644 (file)
@@ -65,7 +65,7 @@ static unsigned long __initdata initrd = EFI_INVALID_TABLE_ADDR;
 extern unsigned long screen_info_table;
 
 struct mm_struct efi_mm = {
-       .mm_mt                  = MTREE_INIT_EXT(mm_mt, MM_MT_FLAGS, efi_mm.mmap_lock),
+       .mm_mt                  = MTREE_INIT(mm_mt, MM_MT_FLAGS),
        .mm_users               = ATOMIC_INIT(2),
        .mm_count               = ATOMIC_INIT(1),
        .write_protect_seq      = SEQCNT_ZERO(efi_mm.write_protect_seq),
index beba5ba0fd978fbf71e7dc91a6c4f3eb0483c71d..99fc2813b0cc32fed3342f0c8ee371f46183cf9e 100644 (file)
@@ -1039,7 +1039,9 @@ static inline int vma_iter_bulk_store(struct vma_iterator *vmi,
 {
        vmi->mas.index = vma->vm_start;
        vmi->mas.last = vma->vm_end - 1;
+       mas_lock(&vmi->mas);
        mas_store(&vmi->mas, vma);
+       mas_unlock(&vmi->mas);
        if (unlikely(mas_is_err(&vmi->mas)))
                return -ENOMEM;
 
index 75e8850cec3adfe0e2d69475d41ff41e03798093..7b5852285d116ebfc140062bf2e1f0eca1c705c2 100644 (file)
@@ -1083,8 +1083,7 @@ struct mm_struct {
        unsigned long cpu_bitmap[];
 };
 
-#define MM_MT_FLAGS    (MT_FLAGS_ALLOC_RANGE | MT_FLAGS_LOCK_EXTERN | \
-                        MT_FLAGS_USE_RCU)
+#define MM_MT_FLAGS    (MT_FLAGS_ALLOC_RANGE | MT_FLAGS_USE_RCU)
 extern struct mm_struct init_mm;
 
 /* Pointer magic because the dynamic array size confuses some compilers. */
index 1b659b07ecd5b3592cff2175b609de58d048caf7..f4943e02d7d8b32bd6446ec7e4258cc3329fbc03 100644 (file)
@@ -661,7 +661,11 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm,
        mm->stack_vm = oldmm->stack_vm;
 
        /* Use __mt_dup() to efficiently build an identical maple tree. */
-       retval = __mt_dup(&oldmm->mm_mt, &mm->mm_mt, GFP_KERNEL);
+       mas_lock(&vmi.mas);
+       rcu_read_lock();
+       retval = __mt_dup(&oldmm->mm_mt, &mm->mm_mt, GFP_KERNEL | GFP_NOWAIT);
+       rcu_read_unlock();
+       mas_unlock(&vmi.mas);
        if (unlikely(retval))
                goto out;
 
@@ -1271,7 +1275,6 @@ static struct mm_struct *mm_init(struct mm_struct *mm, struct task_struct *p,
        struct user_namespace *user_ns)
 {
        mt_init_flags(&mm->mm_mt, MM_MT_FLAGS);
-       mt_set_external_lock(&mm->mm_mt, &mm->mmap_lock);
        atomic_set(&mm->mm_users, 1);
        atomic_set(&mm->mm_count, 1);
        seqcount_init(&mm->write_protect_seq);
index 6af3ad675930be588956591201f52c8b4e7a8f62..c421ef656bb185cf419a4e83c3582896b1940524 100644 (file)
@@ -30,7 +30,7 @@ const struct vm_operations_struct vma_dummy_vm_ops;
  * and size this cpu_bitmask to NR_CPUS.
  */
 struct mm_struct init_mm = {
-       .mm_mt          = MTREE_INIT_EXT(mm_mt, MM_MT_FLAGS, init_mm.mmap_lock),
+       .mm_mt          = MTREE_INIT(mm_mt, MM_MT_FLAGS),
        .pgd            = swapper_pg_dir,
        .mm_users       = ATOMIC_INIT(2),
        .mm_count       = ATOMIC_INIT(1),
index d6bbe435bd990cf4c17aadd8a4b3822b4d1a422c..c1ba9bdadef7331f6dc9ea438e977e682edbb3f8 100644 (file)
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -1274,6 +1274,7 @@ void exit_mmap(struct mm_struct *mm)
                /* Can happen if dup_mmap() received an OOM */
                mmap_read_unlock(mm);
                mmap_write_lock(mm);
+               mas_lock(&vmi.mas);
                goto destroy;
        }
 
@@ -1290,6 +1291,7 @@ void exit_mmap(struct mm_struct *mm)
         */
        set_bit(MMF_OOM_SKIP, &mm->flags);
        mmap_write_lock(mm);
+       mas_lock(&vmi.mas);
        mt_clear_in_rcu(&mm->mm_mt);
        vma_iter_set(&vmi, vma->vm_end);
        free_pgtables(&tlb, &vmi.mas, vma, FIRST_USER_ADDRESS,
@@ -1316,6 +1318,7 @@ void exit_mmap(struct mm_struct *mm)
        trace_exit_mmap(mm);
 destroy:
        __mt_destroy(&mm->mm_mt);
+       mas_unlock(&vmi.mas);
        mmap_write_unlock(mm);
        vm_unacct_memory(nr_accounted);
 }
index 71ca012c616c991ccde38160c05e1828ce581168..c84122a0637e1cef79fb8c1514927c83db782331 100644 (file)
--- a/mm/vma.c
+++ b/mm/vma.c
@@ -581,6 +581,7 @@ void validate_mm(struct mm_struct *mm)
        struct vm_area_struct *vma;
        VMA_ITERATOR(vmi, mm, 0);
 
+       rcu_read_lock();
        mt_validate(&mm->mm_mt);
        for_each_vma(vmi, vma) {
 #ifdef CONFIG_DEBUG_VM_RB
@@ -621,6 +622,8 @@ void validate_mm(struct mm_struct *mm)
                        break;
                }
        }
+       rcu_read_unlock();
+
        if (i != mm->map_count) {
                pr_emerg("map_count %d vma iterator %d\n", mm->map_count, i);
                bug = 1;
index a2e8710b8c479e87702acff9d8e48c3115f37bb6..1b14bbb9afa21a5381dcca597842356e5ef75ea1 100644 (file)
--- a/mm/vma.h
+++ b/mm/vma.h
@@ -148,12 +148,14 @@ static inline int vma_iter_store_gfp(struct vma_iterator *vmi,
                        struct vm_area_struct *vma, gfp_t gfp)
 
 {
+       mas_lock(&vmi->mas);
        if (vmi->mas.status != ma_start &&
            ((vmi->mas.index > vma->vm_start) || (vmi->mas.last < vma->vm_start)))
                vma_iter_invalidate(vmi);
 
        __mas_set_range(&vmi->mas, vma->vm_start, vma->vm_end - 1);
        mas_store_gfp(&vmi->mas, vma, gfp);
+       mas_unlock(&vmi->mas);
        if (unlikely(mas_is_err(&vmi->mas)))
                return -ENOMEM;
 
@@ -350,12 +352,19 @@ static inline int vma_iter_area_highest(struct vma_iterator *vmi, unsigned long
 static inline int vma_iter_prealloc(struct vma_iterator *vmi,
                struct vm_area_struct *vma)
 {
-       return mas_preallocate(&vmi->mas, vma, GFP_KERNEL);
+       int ret;
+
+       mas_lock(&vmi->mas);
+       ret = mas_preallocate(&vmi->mas, vma, GFP_KERNEL | GFP_NOWAIT);
+       mas_unlock(&vmi->mas);
+       return ret;
 }
 
 static inline void vma_iter_clear(struct vma_iterator *vmi)
 {
+       mas_lock(&vmi->mas);
        mas_store_prealloc(&vmi->mas, NULL);
+       mas_unlock(&vmi->mas);
 }
 
 static inline struct vm_area_struct *vma_iter_load(struct vma_iterator *vmi)
@@ -368,6 +377,7 @@ static inline void vma_iter_store(struct vma_iterator *vmi,
                                  struct vm_area_struct *vma)
 {
 
+       mas_lock(&vmi->mas);
 #if defined(CONFIG_DEBUG_VM_MAPLE_TREE)
        if (MAS_WARN_ON(&vmi->mas, vmi->mas.status != ma_start &&
                        vmi->mas.index > vma->vm_start)) {
@@ -389,6 +399,7 @@ static inline void vma_iter_store(struct vma_iterator *vmi,
 
        __mas_set_range(&vmi->mas, vma->vm_start, vma->vm_end - 1);
        mas_store_prealloc(&vmi->mas, vma);
+       mas_unlock(&vmi->mas);
 }
 
 static inline unsigned long vma_iter_addr(struct vma_iterator *vmi)