From: Liam R. Howlett Date: Tue, 8 Apr 2025 19:37:27 +0000 (-0400) Subject: there are issues here X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=5bc5da499c44768daf27538249ff0108c1c6859a;p=users%2Fjedix%2Flinux-maple.git there are issues here Signed-off-by: Liam R. Howlett --- diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c index 46b8f1f16676..164aa0050b6e 100644 --- a/arch/x86/kernel/tboot.c +++ b/arch/x86/kernel/tboot.c @@ -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), diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c index 7309394b8fc9..c70554a3a54e 100644 --- a/drivers/firmware/efi/efi.c +++ b/drivers/firmware/efi/efi.c @@ -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), diff --git a/include/linux/mm.h b/include/linux/mm.h index beba5ba0fd97..99fc2813b0cc 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -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; diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h index 75e8850cec3a..7b5852285d11 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -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. */ diff --git a/kernel/fork.c b/kernel/fork.c index 1b659b07ecd5..f4943e02d7d8 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -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); diff --git a/mm/init-mm.c b/mm/init-mm.c index 6af3ad675930..c421ef656bb1 100644 --- a/mm/init-mm.c +++ b/mm/init-mm.c @@ -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), diff --git a/mm/mmap.c b/mm/mmap.c index d6bbe435bd99..c1ba9bdadef7 100644 --- 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); } diff --git a/mm/vma.c b/mm/vma.c index 71ca012c616c..c84122a0637e 100644 --- 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; diff --git a/mm/vma.h b/mm/vma.h index a2e8710b8c47..1b14bbb9afa2 100644 --- 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)