Add a new mmap locking API wrapping mmap_sem calls
Subsystems (85)
v3 cover Add a new mmap locking API wrapping mmap_sem calls
This patch series adds a new mmap locking API replacing the existing mmap_sem lock and unlocks. Initially the API is just implemente in terms of inlined rwsem calls, so it doesn't provide any new functionality.
There are two justifications for the new API:
- At first, it provides an easy hooking point to instrument mmap_sem locking latencies independently of any other rwsems.
- In the future, it may be a starting point for replacing the rwsem implementation with a different one, such as range locks. This is something that is being explored, even though there is no wide concensus about this possible direction yet.
(see https://patchwork.kernel.org/cover/11401483/)
Changes since v2 of the patchset:
- Removed the mmap_is_locked API - v2 had removed all uses of it, but the actual function definition was still there unused. Thanks to Jason Gunthorpe for noticing the unused mmap_is_locked function.
Changes since v1 of the patchset:
- Manually convert drivers/dma-buf/dma-resv.c ahead of the automated coccinelle conversion as this file requires a new include statement. Thanks to Intel's kbuild test bot for finding the issue.
- In coccinelle automated conversion, apply a single coccinelle rule as suggested by Markus Elfring.
- In manual conversion of sites missed by coccinelle, fix an issue where I had used mm_read_unlock (from an older version of my patchset) instead of mmap_read_unlock in some arch/mips code.
This was also identified by Intel's kbuild test bot.
- Do not add a new mmap_is_locked API, and use lockdep_assert_held instead. Thanks to Jason Gunthorpe and Matthew Wilcox for the suggestion.
The changes apply on top of v5.6-rc7.
I think it would be feasible to push these changes towards mainline if given sufficient approval. The coccinelle part of the change is relatively invasive, but can be skipped over on a file by file basis if it causes any conflicts with other pending changes. The new mmap locking API can interoperate with new code that is still using direct rwsem calls, until the last patch in the series which renames mmap_sem to enforce using the new API. Maybe that last patch could be delayed for a bit, so that we'd get a chance to convert any new code that locks mmap_sem in the -rc1 release before applying that last patch.
Michel Lespinasse (10):
mmap locking API: initial implementation as rwsem wrappers
MMU notifier: use the new mmap locking API
DMA reservations: use the new mmap locking API
mmap locking API: use coccinelle to convert mmap_sem rwsem call sites mmap locking API: convert mmap_sem call sites missed by coccinelle mmap locking API: convert nested write lock sites
mmap locking API: add mmap_read_release() and mmap_read_unlock_non_owner() mmap locking API: add MMAP_LOCK_INITIALIZER
mmap locking API: use lockdep_assert_held
mmap locking API: rename mmap_sem to mmap_lock
arch/alpha/kernel/traps.c | 4 +- arch/alpha/mm/fault.c | 10 +-- arch/arc/kernel/process.c | 4 +- arch/arc/kernel/troubleshoot.c | 4 +- arch/arc/mm/fault.c | 4 +- arch/arm/kernel/process.c | 4 +- arch/arm/kernel/swp_emulate.c | 4 +- arch/arm/lib/uaccess_with_memcpy.c | 16 ++-- arch/arm/mm/fault.c | 6 +- arch/arm64/kernel/traps.c | 4 +- arch/arm64/kernel/vdso.c | 8 +- arch/arm64/mm/fault.c | 8 +- arch/csky/kernel/vdso.c | 4 +- arch/csky/mm/fault.c | 8 +- arch/hexagon/kernel/vdso.c | 4 +- arch/hexagon/mm/vm_fault.c | 8 +- arch/ia64/kernel/perfmon.c | 8 +- arch/ia64/mm/fault.c | 12 +-- arch/ia64/mm/init.c | 12 +-- arch/m68k/kernel/sys_m68k.c | 14 ++-- arch/m68k/mm/fault.c | 8 +- arch/microblaze/mm/fault.c | 12 +-- arch/mips/kernel/traps.c | 4 +- arch/mips/kernel/vdso.c | 4 +- arch/mips/mm/fault.c | 10 +-- arch/nds32/kernel/vdso.c | 6 +- arch/nds32/mm/fault.c | 12 +-- arch/nios2/mm/fault.c | 12 +-- arch/nios2/mm/init.c | 4 +- arch/openrisc/mm/fault.c | 10 +-- arch/parisc/kernel/traps.c | 6 +- arch/parisc/mm/fault.c | 8 +- arch/powerpc/kernel/vdso.c | 6 +- arch/powerpc/kvm/book3s_64_mmu_hv.c | 4 +- arch/powerpc/kvm/book3s_hv.c | 6 +- arch/powerpc/kvm/book3s_hv_uvmem.c | 12 +-- arch/powerpc/kvm/e500_mmu_host.c | 4 +- arch/powerpc/mm/book3s64/iommu_api.c | 4 +- arch/powerpc/mm/book3s64/subpage_prot.c | 12 +-- arch/powerpc/mm/copro_fault.c | 4 +- arch/powerpc/mm/fault.c | 12 +-- arch/powerpc/oprofile/cell/spu_task_sync.c | 6 +- arch/powerpc/platforms/cell/spufs/file.c | 4 +- arch/riscv/kernel/vdso.c | 4 +- arch/riscv/mm/fault.c | 10 +-- arch/s390/kernel/vdso.c | 4 +- arch/s390/kvm/gaccess.c | 4 +- arch/s390/kvm/kvm-s390.c | 24 +++--- arch/s390/kvm/priv.c | 32 ++++---- arch/s390/mm/fault.c | 6 +- arch/s390/mm/gmap.c | 40 +++++----- arch/s390/pci/pci_mmio.c | 4 +- arch/sh/kernel/sys_sh.c | 6 +- arch/sh/kernel/vsyscall/vsyscall.c | 4 +- arch/sh/mm/fault.c | 14 ++-- arch/sparc/mm/fault_32.c | 18 ++--- arch/sparc/mm/fault_64.c | 12 +-- arch/sparc/vdso/vma.c | 4 +- arch/um/include/asm/mmu_context.h | 5 +- arch/um/kernel/tlb.c | 2 +- arch/um/kernel/trap.c | 6 +- arch/unicore32/mm/fault.c | 6 +- arch/x86/entry/vdso/vma.c | 14 ++-- arch/x86/events/core.c | 4 +- arch/x86/kernel/tboot.c | 2 +- arch/x86/kernel/vm86_32.c | 4 +- arch/x86/kvm/mmu/paging_tmpl.h | 8 +- arch/x86/mm/fault.c | 10 +-- arch/x86/um/vdso/vma.c | 4 +- arch/xtensa/mm/fault.c | 10 +-- drivers/android/binder_alloc.c | 10 +-- drivers/dma-buf/dma-resv.c | 5 +- drivers/firmware/efi/efi.c | 2 +- .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 4 +- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 10 +-- drivers/gpu/drm/amd/amdkfd/kfd_events.c | 4 +- drivers/gpu/drm/etnaviv/etnaviv_gem.c | 2 +- drivers/gpu/drm/i915/gem/i915_gem_mman.c | 4 +- drivers/gpu/drm/i915/gem/i915_gem_userptr.c | 8 +- drivers/gpu/drm/nouveau/nouveau_svm.c | 20 ++--- drivers/gpu/drm/radeon/radeon_cs.c | 4 +- drivers/gpu/drm/radeon/radeon_gem.c | 6 +- drivers/gpu/drm/ttm/ttm_bo_vm.c | 4 +- drivers/infiniband/core/umem_odp.c | 4 +- drivers/infiniband/core/uverbs_main.c | 4 +- drivers/infiniband/hw/mlx4/mr.c | 4 +- drivers/infiniband/hw/qib/qib_user_pages.c | 6 +- drivers/infiniband/hw/usnic/usnic_uiom.c | 4 +- drivers/infiniband/sw/siw/siw_mem.c | 4 +- drivers/iommu/amd_iommu_v2.c | 4 +- drivers/iommu/intel-svm.c | 4 +- drivers/media/v4l2-core/videobuf-core.c | 4 +- drivers/media/v4l2-core/videobuf-dma-contig.c | 4 +- drivers/media/v4l2-core/videobuf-dma-sg.c | 4 +- drivers/misc/cxl/cxllib.c | 4 +- drivers/misc/cxl/fault.c | 4 +- drivers/misc/sgi-gru/grufault.c | 16 ++-- drivers/misc/sgi-gru/grufile.c | 4 +- drivers/oprofile/buffer_sync.c | 10 +-- drivers/staging/kpc2000/kpc_dma/fileops.c | 4 +- drivers/tee/optee/call.c | 4 +- drivers/vfio/vfio_iommu_type1.c | 8 +- drivers/xen/gntdev.c | 4 +- drivers/xen/privcmd.c | 14 ++-- fs/aio.c | 4 +- fs/coredump.c | 4 +- fs/exec.c | 16 ++-- fs/io_uring.c | 4 +- fs/proc/base.c | 18 ++--- fs/proc/task_mmu.c | 28 +++---- fs/proc/task_nommu.c | 18 ++--- fs/userfaultfd.c | 28 +++---- include/linux/mm.h | 1 + include/linux/mm_types.h | 2 +- include/linux/mmap_lock.h | 77 +++++++++++++++++++ include/linux/mmu_notifier.h | 5 +- ipc/shm.c | 8 +- kernel/acct.c | 4 +- kernel/bpf/stackmap.c | 13 ++-- kernel/events/core.c | 4 +- kernel/events/uprobes.c | 16 ++-- kernel/exit.c | 8 +- kernel/fork.c | 14 ++-- kernel/futex.c | 4 +- kernel/sched/fair.c | 4 +- kernel/sys.c | 18 ++--- kernel/trace/trace_output.c | 4 +- mm/filemap.c | 6 +- mm/frame_vector.c | 4 +- mm/gup.c | 20 ++--- mm/hmm.c | 2 +- mm/init-mm.c | 2 +- mm/internal.h | 2 +- mm/khugepaged.c | 36 ++++----- mm/ksm.c | 34 ++++---- mm/madvise.c | 18 ++--- mm/memcontrol.c | 8 +- mm/memory.c | 14 ++-- mm/mempolicy.c | 22 +++--- mm/migrate.c | 8 +- mm/mincore.c | 4 +- mm/mlock.c | 16 ++-- mm/mmap.c | 36 ++++----- mm/mmu_notifier.c | 22 +++--- mm/mprotect.c | 12 +-- mm/mremap.c | 6 +- mm/msync.c | 8 +- mm/nommu.c | 16 ++-- mm/oom_kill.c | 4 +- mm/pagewalk.c | 15 ++-- mm/process_vm_access.c | 4 +- mm/ptdump.c | 4 +- mm/swapfile.c | 4 +- mm/userfaultfd.c | 14 ++-- mm/util.c | 12 +-- net/ipv4/tcp.c | 4 +- net/xdp/xdp_umem.c | 4 +- virt/kvm/arm/mmu.c | 14 ++-- virt/kvm/async_pf.c | 4 +- virt/kvm/kvm_main.c | 8 +- 160 files changed, 774 insertions(+), 693 deletions(-) create mode 100644 include/linux/mmap_lock.h
Signature · 1 line
2.26.0.rc2.310.g2932bb562d-goog
PATCH v3 1/10 mmap locking API: initial implementation as rwsem wrappers
This change wraps the existing mmap_sem related rwsem calls into a new mmap locking API. There are two justifications for the new API:
- At first, it provides an easy hooking point to instrument mmap_sem locking latencies independently of any other rwsems.
- In the future, it may be a starting point for replacing the rwsem implementation with a different one, such as range locks.
--- include/linux/mm.h | 1 + include/linux/mmap_lock.h | 54 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 include/linux/mmap_lock.h
include/linux/mm.h +1 -0
@@ -15,6 +15,7 @@#include <linux/atomic.h> #include <linux/debug_locks.h> #include <linux/mm_types.h> +#include <linux/mmap_lock.h> #include <linux/range.h> #include <linux/pfn.h> #include <linux/percpu-refcount.h>
include/linux/mmap_lock.h new file +54 -0
54 lines not on this page · raw message
Signature · 1 line
2.26.0.rc2.310.g2932bb562d-goog
PATCH v3 2/10 MMU notifier: use the new mmap locking API
In reply to Michel LespinasseThis use is converted manually ahead of the next patch in the series, as it requires including a new header which the automated conversion would miss.
--- include/linux/mmu_notifier.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
include/linux/mmu_notifier.h +3 -2
@@ -5,6 +5,7 @@#include <linux/list.h> #include <linux/spinlock.h> #include <linux/mm_types.h> +#include <linux/mmap_lock.h> #include <linux/srcu.h> #include <linux/interval_tree.h>
@@ -277,9 +278,9 @@ mmu_notifier_get(const struct mmu_notifier_ops *ops, struct mm_struct *mm) {struct mmu_notifier *ret; -down_write (&mm->mmap_sem); +mmap_write_lock (mm); ret =mmu_notifier_get_locked (ops, mm); -up_write (&mm->mmap_sem); +mmap_write_unlock (mm);return ret; }void mmu_notifier_put (struct mmu_notifier *subscription);
Signature · 1 line
2.26.0.rc2.310.g2932bb562d-goog
PATCH v3 3/10 DMA reservations: use the new mmap locking API
In reply to Michel LespinasseThis use is converted manually ahead of the next patch in the series, as it requires including a new header which the automated conversion would miss.
--- drivers/dma-buf/dma-resv.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/dma-buf/dma-resv.c +3 -2
@@ -34,6 +34,7 @@#include <linux/dma-resv.h> #include <linux/export.h> +#include <linux/mm.h> #include <linux/sched/mm.h> /**
@@ -109,7 +110,7 @@ static int __init dma_resv_lockdep(void)dma_resv_init (&obj); -down_read (&mm->mmap_sem); +mmap_read_lock (mm);ww_acquire_init (&ctx, &reservation_ww_class); ret =dma_resv_lock (&obj, &ctx);if (ret == -EDEADLK )
@@ -118,7 +119,7 @@ static int __init dma_resv_lockdep(void)fs_reclaim_release (GFP_KERNEL );ww_mutex_unlock (&obj.lock);ww_acquire_fini (&ctx); -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);mmput (mm);
Signature · 1 line
2.26.0.rc2.310.g2932bb562d-goog
PATCH v3 5/10 mmap locking API: convert mmap_sem call sites missed by coccinelle
In reply to Michel LespinasseConvert the last few remaining mmap_sem rwsem calls to use the new mmap locking API. These were missed by coccinelle for some reason (I think coccinelle does not support some of the preprocessor constructs in these files ?)
--- arch/mips/mm/fault.c | 10 +++++----- arch/x86/kvm/mmu/paging_tmpl.h | 8 ++++---- drivers/android/binder_alloc.c | 4 ++-- fs/proc/base.c | 6 +++--- 4 files changed, 14 insertions(+), 14 deletions(-)
arch/mips/mm/fault.c +5 -5
@@ -97,7 +97,7 @@ static void __kprobes __do_page_fault(struct pt_regs *regs, unsigned long write,if (user_mode (regs)) flags |=FAULT_FLAG_USER ; retry: -down_read (&mm->mmap_sem); +mmap_read_lock (mm); vma =find_vma (mm, address);if (!vma) goto bad_area;
@@ -191,7 +191,7 @@ static void __kprobes __do_page_fault(struct pt_regs *regs, unsigned long write, } } -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);return ;/*
@@ -199,7 +199,7 @@ static void __kprobes __do_page_fault(struct pt_regs *regs, unsigned long write,* Fix it, but check if it's kernel or user first.. */ bad_area: -up_read (&mm->mmap_sem); +mmap_read_unlock (mm); bad_area_nosemaphore:/* User mode accesses just cause a SIGSEGV */
@@ -251,14 +251,14 @@ static void __kprobes __do_page_fault(struct pt_regs *regs, unsigned long write,* We ran out of memory, call the OOM killer, and return the userspace * (which will retry the fault, or kill us if we got oom-killed). */ -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);if (!user_mode (regs)) goto no_context;pagefault_out_of_memory ();return ; do_sigbus: -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);/* Kernel mode? Handle exceptions or die */ if (!user_mode (regs))
arch/x86/kvm/mmu/paging_tmpl.h +4 -4
@@ -165,22 +165,22 @@ static int FNAME(cmpxchg_gpte)(struct kvm_vcpu *vcpu, struct kvm_mmu *mmu,unsigned long pfn;unsigned long paddr; -down_read (¤t->mm->mmap_sem); +mmap_read_lock (current->mm); vma =find_vma_intersection (current->mm, vaddr, vaddr +PAGE_SIZE );if (!vma || !(vma->vm_flags &VM_PFNMAP )) { -up_read (¤t->mm->mmap_sem); +mmap_read_unlock (current->mm);return -EFAULT ; } pfn = ((vaddr - vma->vm_start) >>PAGE_SHIFT ) + vma->vm_pgoff; paddr = pfn <<PAGE_SHIFT ; table =memremap (paddr,PAGE_SIZE ,MEMREMAP_WB );if (!table) { -up_read (¤t->mm->mmap_sem); +mmap_read_unlock (current->mm);return -EFAULT ; } ret =CMPXCHG (&table[index], orig_pte, new_pte);memunmap (table); -up_read (¤t->mm->mmap_sem); +mmap_read_unlock (current->mm); }return (ret != orig_pte);
drivers/android/binder_alloc.c +2 -2
@@ -932,7 +932,7 @@ enum lru_status binder_alloc_free_page(struct list_head *item, mm = alloc->vma_vm_mm;if (!mmget_not_zero (mm)) goto err_mmget; -if (!down_read_trylock (&mm->mmap_sem)) +if (!mmap_read_trylock (mm)) goto err_down_read_mmap_sem_failed; vma =binder_alloc_get_vma (alloc);
@@ -946,7 +946,7 @@ enum lru_status binder_alloc_free_page(struct list_head *item,trace_binder_unmap_user_end (alloc, index); } -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);mmput (mm);trace_binder_unmap_kernel_start (alloc, index);
fs/proc/base.c +3 -3
@@ -2280,7 +2280,7 @@ proc_map_files_readdir(struct file *file, struct dir_context *ctx)if (!mm) goto out_put_task; - ret =down_read_killable (&mm->mmap_sem); + ret =mmap_read_lock_killable (mm);if (ret) {mmput (mm); goto out_put_task;
@@ -2307,7 +2307,7 @@ proc_map_files_readdir(struct file *file, struct dir_context *ctx) p =genradix_ptr_alloc (&fa, nr_files++,GFP_KERNEL );if (!p) { ret = -ENOMEM ; -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);mmput (mm); goto out_put_task; }
@@ -2316,7 +2316,7 @@ proc_map_files_readdir(struct file *file, struct dir_context *ctx) p->end = vma->vm_end; p->mode = vma->vm_file->f_mode; } -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);mmput (mm);for (i =0 ; i < nr_files; i++) {
Signature · 1 line
2.26.0.rc2.310.g2932bb562d-goog
PATCH v3 4/10 mmap locking API: use coccinelle to convert mmap_sem rwsem call sites
In reply to Michel LespinasseThis change converts the existing mmap_sem rwsem calls to use the new mmap locking API instead.
The change is generated using coccinelle with the following rule:
// spatch --sp-file mmap_lock_api.cocci --in-place --include-headers --dir .
@@
expression mm;
@@
(
-init_rwsem
+mmap_init_lock
|
-down_write
+mmap_write_lock
|
-down_write_killable
+mmap_write_lock_killable
|
-down_write_trylock
+mmap_write_trylock
|
-up_write
+mmap_write_unlock
|
-downgrade_write
+mmap_downgrade_write_lock
|
-down_read
+mmap_read_lock
|
-down_read_killable
+mmap_read_lock_killable
|
-down_read_trylock
+mmap_read_trylock
|
-up_read
+mmap_read_unlock
)
-(&mm->mmap_sem)
+(mm)
--- arch/alpha/kernel/traps.c | 4 +- arch/alpha/mm/fault.c | 10 ++--- arch/arc/kernel/process.c | 4 +- arch/arc/kernel/troubleshoot.c | 4 +- arch/arc/mm/fault.c | 4 +- arch/arm/kernel/process.c | 4 +- arch/arm/kernel/swp_emulate.c | 4 +- arch/arm/lib/uaccess_with_memcpy.c | 16 ++++---- arch/arm/mm/fault.c | 6 +-- arch/arm64/kernel/traps.c | 4 +- arch/arm64/kernel/vdso.c | 8 ++-- arch/arm64/mm/fault.c | 8 ++-- arch/csky/kernel/vdso.c | 4 +- arch/csky/mm/fault.c | 8 ++-- arch/hexagon/kernel/vdso.c | 4 +- arch/hexagon/mm/vm_fault.c | 8 ++-- arch/ia64/kernel/perfmon.c | 8 ++-- arch/ia64/mm/fault.c | 8 ++-- arch/ia64/mm/init.c | 12 +++--- arch/m68k/kernel/sys_m68k.c | 14 +++---- arch/m68k/mm/fault.c | 8 ++-- arch/microblaze/mm/fault.c | 12 +++--- arch/mips/kernel/traps.c | 4 +- arch/mips/kernel/vdso.c | 4 +- arch/nds32/kernel/vdso.c | 6 +-- arch/nds32/mm/fault.c | 12 +++--- arch/nios2/mm/fault.c | 12 +++--- arch/nios2/mm/init.c | 4 +- arch/openrisc/mm/fault.c | 10 ++--- arch/parisc/kernel/traps.c | 6 +-- arch/parisc/mm/fault.c | 8 ++-- arch/powerpc/kernel/vdso.c | 6 +-- arch/powerpc/kvm/book3s_64_mmu_hv.c | 4 +- arch/powerpc/kvm/book3s_hv.c | 6 +-- arch/powerpc/kvm/book3s_hv_uvmem.c | 12 +++--- arch/powerpc/kvm/e500_mmu_host.c | 4 +- arch/powerpc/mm/book3s64/iommu_api.c | 4 +- arch/powerpc/mm/book3s64/subpage_prot.c | 12 +++--- arch/powerpc/mm/copro_fault.c | 4 +- arch/powerpc/mm/fault.c | 12 +++--- arch/powerpc/oprofile/cell/spu_task_sync.c | 6 +-- arch/powerpc/platforms/cell/spufs/file.c | 4 +- arch/riscv/kernel/vdso.c | 4 +- arch/riscv/mm/fault.c | 10 ++--- arch/s390/kernel/vdso.c | 4 +- arch/s390/kvm/gaccess.c | 4 +- arch/s390/kvm/kvm-s390.c | 24 +++++------ arch/s390/kvm/priv.c | 32 +++++++-------- arch/s390/mm/fault.c | 6 +-- arch/s390/mm/gmap.c | 40 +++++++++---------- arch/s390/pci/pci_mmio.c | 4 +- arch/sh/kernel/sys_sh.c | 6 +-- arch/sh/kernel/vsyscall/vsyscall.c | 4 +- arch/sh/mm/fault.c | 14 +++---- arch/sparc/mm/fault_32.c | 18 ++++----- arch/sparc/mm/fault_64.c | 12 +++--- arch/sparc/vdso/vma.c | 4 +- arch/um/include/asm/mmu_context.h | 2 +- arch/um/kernel/tlb.c | 2 +- arch/um/kernel/trap.c | 6 +-- arch/unicore32/mm/fault.c | 6 +-- arch/x86/entry/vdso/vma.c | 14 +++---- arch/x86/kernel/vm86_32.c | 4 +- arch/x86/mm/fault.c | 8 ++-- arch/x86/um/vdso/vma.c | 4 +- arch/xtensa/mm/fault.c | 10 ++--- drivers/android/binder_alloc.c | 6 +-- .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 4 +- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 10 ++--- drivers/gpu/drm/amd/amdkfd/kfd_events.c | 4 +- drivers/gpu/drm/i915/gem/i915_gem_mman.c | 4 +- drivers/gpu/drm/i915/gem/i915_gem_userptr.c | 8 ++-- drivers/gpu/drm/nouveau/nouveau_svm.c | 20 +++++----- drivers/gpu/drm/radeon/radeon_cs.c | 4 +- drivers/gpu/drm/radeon/radeon_gem.c | 6 +-- drivers/gpu/drm/ttm/ttm_bo_vm.c | 4 +- drivers/infiniband/core/umem_odp.c | 4 +- drivers/infiniband/core/uverbs_main.c | 4 +- drivers/infiniband/hw/mlx4/mr.c | 4 +- drivers/infiniband/hw/qib/qib_user_pages.c | 6 +-- drivers/infiniband/hw/usnic/usnic_uiom.c | 4 +- drivers/infiniband/sw/siw/siw_mem.c | 4 +- drivers/iommu/amd_iommu_v2.c | 4 +- drivers/iommu/intel-svm.c | 4 +- drivers/media/v4l2-core/videobuf-core.c | 4 +- drivers/media/v4l2-core/videobuf-dma-contig.c | 4 +- drivers/media/v4l2-core/videobuf-dma-sg.c | 4 +- drivers/misc/cxl/cxllib.c | 4 +- drivers/misc/cxl/fault.c | 4 +- drivers/misc/sgi-gru/grufault.c | 16 ++++---- drivers/misc/sgi-gru/grufile.c | 4 +- drivers/oprofile/buffer_sync.c | 10 ++--- drivers/staging/kpc2000/kpc_dma/fileops.c | 4 +- drivers/tee/optee/call.c | 4 +- drivers/vfio/vfio_iommu_type1.c | 8 ++-- drivers/xen/gntdev.c | 4 +- drivers/xen/privcmd.c | 14 +++---- fs/aio.c | 4 +- fs/coredump.c | 4 +- fs/exec.c | 16 ++++---- fs/io_uring.c | 4 +- fs/proc/base.c | 12 +++--- fs/proc/task_mmu.c | 28 ++++++------- fs/proc/task_nommu.c | 18 ++++----- fs/userfaultfd.c | 22 +++++----- ipc/shm.c | 8 ++-- kernel/acct.c | 4 +- kernel/bpf/stackmap.c | 4 +- kernel/events/core.c | 4 +- kernel/events/uprobes.c | 16 ++++---- kernel/exit.c | 8 ++-- kernel/fork.c | 12 +++--- kernel/futex.c | 4 +- kernel/sched/fair.c | 4 +- kernel/sys.c | 18 ++++----- kernel/trace/trace_output.c | 4 +- mm/filemap.c | 6 +-- mm/frame_vector.c | 4 +- mm/gup.c | 18 ++++----- mm/internal.h | 2 +- mm/khugepaged.c | 36 ++++++++--------- mm/ksm.c | 34 ++++++++-------- mm/madvise.c | 18 ++++----- mm/memcontrol.c | 8 ++-- mm/memory.c | 10 ++--- mm/mempolicy.c | 22 +++++----- mm/migrate.c | 8 ++-- mm/mincore.c | 4 +- mm/mlock.c | 16 ++++---- mm/mmap.c | 32 +++++++-------- mm/mmu_notifier.c | 4 +- mm/mprotect.c | 12 +++--- mm/mremap.c | 6 +-- mm/msync.c | 8 ++-- mm/nommu.c | 16 ++++---- mm/oom_kill.c | 4 +- mm/process_vm_access.c | 4 +- mm/ptdump.c | 4 +- mm/swapfile.c | 4 +- mm/userfaultfd.c | 14 +++---- mm/util.c | 8 ++-- net/ipv4/tcp.c | 4 +- net/xdp/xdp_umem.c | 4 +- virt/kvm/arm/mmu.c | 14 +++---- virt/kvm/async_pf.c | 4 +- virt/kvm/kvm_main.c | 8 ++-- 146 files changed, 631 insertions(+), 631 deletions(-)
arch/alpha/kernel/traps.c +2 -2
@@ -957,12 +957,12 @@ do_entUnaUser(void __user * va, unsigned long opcode, si_code =SEGV_ACCERR ; else {struct mm_struct *mm = current->mm; -down_read (&mm->mmap_sem); +mmap_read_lock (mm);if (find_vma (mm, (unsigned long )va)) si_code =SEGV_ACCERR ;else si_code =SEGV_MAPERR ; -up_read (&mm->mmap_sem); +mmap_read_unlock (mm); }send_sig_fault (SIGSEGV , si_code, va,0 , current);return ;
arch/alpha/mm/fault.c +5 -5
@@ -117,7 +117,7 @@ do_page_fault(unsigned long address, unsigned long mmcsr,if (user_mode (regs)) flags |=FAULT_FLAG_USER ; retry: -down_read (&mm->mmap_sem); +mmap_read_lock (mm); vma =find_vma (mm, address);if (!vma) goto bad_area;
@@ -180,14 +180,14 @@ do_page_fault(unsigned long address, unsigned long mmcsr, } } -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);return ;/* Something tried to access memory that isn't in our memory map. Fix it, but check if it's kernel or user first. */ bad_area: -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);if (user_mode (regs)) goto do_sigsegv;
@@ -211,14 +211,14 @@ do_page_fault(unsigned long address, unsigned long mmcsr,/* We ran out of memory, or some other thing happened to us that made us unable to handle the page fault gracefully. */ out_of_memory: -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);if (!user_mode (regs)) goto no_context;pagefault_out_of_memory ();return ; do_sigbus: -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);/* Send a sigbus, regardless of whether we were in kernel or user mode. */ force_sig_fault (SIGBUS ,BUS_ADRERR , (void __user *) address,0 );
arch/arc/kernel/process.c +2 -2
@@ -90,10 +90,10 @@ SYSCALL_DEFINE3(arc_usr_cmpxchg, int *, uaddr, int, expected, int, new)if (unlikely (ret != -EFAULT )) goto fail; -down_read (¤t->mm->mmap_sem); +mmap_read_lock (current->mm); ret =fixup_user_fault (current, current->mm, (unsigned long ) uaddr,FAULT_FLAG_WRITE ,NULL ); -up_read (¤t->mm->mmap_sem); +mmap_read_unlock (current->mm);if (likely (!ret)) goto again;
arch/arc/kernel/troubleshoot.c +2 -2
@@ -89,7 +89,7 @@ static void show_faulting_vma(unsigned long address)/* can't use print_vma_addr() yet as it doesn't check for * non-inclusive vma */ -down_read (&active_mm->mmap_sem); +mmap_read_lock (active_mm); vma =find_vma (active_mm, address);/* check against the find_vma( ) behaviour which returns the next VMA
@@ -111,7 +111,7 @@ static void show_faulting_vma(unsigned long address) }else pr_info (" @No matching VMA found\n" ); -up_read (&active_mm->mmap_sem); +mmap_read_unlock (active_mm); }static void show_ecr_verbose (struct pt_regs *regs)
arch/arc/mm/fault.c +2 -2
@@ -107,7 +107,7 @@ void do_page_fault(unsigned long address, struct pt_regs *regs) flags |=FAULT_FLAG_WRITE ; retry: -down_read (&mm->mmap_sem); +mmap_read_lock (mm); vma =find_vma (mm, address);if (!vma)
@@ -159,7 +159,7 @@ void do_page_fault(unsigned long address, struct pt_regs *regs) } bad_area: -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);/* * Major/minor page fault accounting
arch/arm/kernel/process.c +2 -2
@@ -431,7 +431,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp) npages =1 ;/* for sigpage */ npages += vdso_total_pages; -if (down_write_killable (&mm->mmap_sem)) +if (mmap_write_lock_killable (mm))return -EINTR ; hint =sigpage_addr (mm, npages); addr =get_unmapped_area (NULL , hint, npages <<PAGE_SHIFT ,0 ,0 );
@@ -458,7 +458,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)arm_install_vdso (mm, addr +PAGE_SIZE ); up_fail: -up_write (&mm->mmap_sem); +mmap_write_unlock (mm); return ret; }#endif
arch/arm/kernel/swp_emulate.c +2 -2
@@ -97,12 +97,12 @@ static void set_segfault(struct pt_regs *regs, unsigned long addr) {int si_code; -down_read (¤t->mm->mmap_sem); +mmap_read_lock (current->mm);if (find_vma (current->mm, addr) ==NULL ) si_code =SEGV_MAPERR ;else si_code =SEGV_ACCERR ; -up_read (¤t->mm->mmap_sem); +mmap_read_unlock (current->mm);pr_debug ("SWP{B} emulation: access caused memory abort!\n" ); arm_notify_die("Illegal memory access", regs,
arch/arm/lib/uaccess_with_memcpy.c +8 -8
@@ -96,7 +96,7 @@ __copy_to_user_memcpy(void __user *to, const void *from, unsigned long n) atomic =faulthandler_disabled ();if (!atomic) -down_read (¤t->mm->mmap_sem); +mmap_read_lock (current->mm);while (n) {pte_t *pte;spinlock_t *ptl;
@@ -104,11 +104,11 @@ __copy_to_user_memcpy(void __user *to, const void *from, unsigned long n)while (!pin_page_for_write (to, &pte, &ptl)) {if (!atomic) -up_read (¤t->mm->mmap_sem); +mmap_read_unlock (current->mm);if (__put_user (0 , (char __user *)to)) goto out;if (!atomic) -down_read (¤t->mm->mmap_sem); +mmap_read_lock (current->mm); } tocopy = (~(unsigned long )to & ~PAGE_MASK ) +1 ;
@@ -128,7 +128,7 @@ __copy_to_user_memcpy(void __user *to, const void *from, unsigned long n)spin_unlock (ptl); }if (!atomic) -up_read (¤t->mm->mmap_sem); +mmap_read_unlock (current->mm); out:return n;
@@ -165,17 +165,17 @@ __clear_user_memset(void __user *addr, unsigned long n)return 0 ; } -down_read (¤t->mm->mmap_sem); +mmap_read_lock (current->mm);while (n) {pte_t *pte;spinlock_t *ptl;int tocopy;while (!pin_page_for_write (addr, &pte, &ptl)) { -up_read (¤t->mm->mmap_sem); +mmap_read_unlock (current->mm);if (__put_user (0 , (char __user *)addr)) goto out; -down_read (¤t->mm->mmap_sem); +mmap_read_lock (current->mm); } tocopy = (~(unsigned long )addr & ~PAGE_MASK ) +1 ;
@@ -193,7 +193,7 @@ __clear_user_memset(void __user *addr, unsigned long n)else spin_unlock (ptl); } -up_read (¤t->mm->mmap_sem); +mmap_read_unlock (current->mm); out:return n;
arch/arm/mm/fault.c +3 -3
@@ -270,11 +270,11 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)* validly references user space from well defined areas of the code, * we can bug out early if this is from code which shouldn't. */ -if (!down_read_trylock (&mm->mmap_sem)) { +if (!mmap_read_trylock (mm)) {if (!user_mode (regs) && !search_exception_tables (regs->ARM_pc)) goto no_context; retry: -down_read (&mm->mmap_sem); +mmap_read_lock (mm); }else {/* * The above down_read_trylock() might have succeeded in
@@ -327,7 +327,7 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs) } } -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);/* * Handle the "normal" case first - VM_FAULT_MAJOR
arch/arm64/kernel/traps.c +2 -2
@@ -387,12 +387,12 @@ void arm64_notify_segfault(unsigned long addr) {int code; -down_read (¤t->mm->mmap_sem); +mmap_read_lock (current->mm);if (find_vma (current->mm, addr) ==NULL ) code =SEGV_MAPERR ;else code =SEGV_ACCERR ; -up_read (¤t->mm->mmap_sem); +mmap_read_unlock (current->mm);force_signal_inject (SIGSEGV , code, addr); }
arch/arm64/kernel/vdso.c +4 -4
@@ -357,7 +357,7 @@ int aarch32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)struct mm_struct *mm = current->mm;int ret; -if (down_write_killable (&mm->mmap_sem)) +if (mmap_write_lock_killable (mm))return -EINTR ; ret =aarch32_kuser_helpers_setup (mm);
@@ -374,7 +374,7 @@ int aarch32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)#endif /* CONFIG_COMPAT_VDSO */ out: -up_write (&mm->mmap_sem); +mmap_write_unlock (mm); return ret; }#endif /* CONFIG_COMPAT */
@@ -418,7 +418,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm,struct mm_struct *mm = current->mm;int ret; -if (down_write_killable (&mm->mmap_sem)) +if (mmap_write_lock_killable (mm))return -EINTR ; ret = __setup_additional_pages(ARM64_VDSO,
@@ -426,7 +426,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, bprm, uses_interp); -up_write (&mm->mmap_sem); +mmap_write_unlock (mm);return ret; }
arch/arm64/mm/fault.c +4 -4
@@ -491,11 +491,11 @@ static int __kprobes do_page_fault(unsigned long addr, unsigned int esr,* validly references user space from well defined areas of the code, * we can bug out early if this is from code which shouldn't. */ -if (!down_read_trylock (&mm->mmap_sem)) { +if (!mmap_read_trylock (mm)) {if (!user_mode (regs) && !search_exception_tables (regs->pc)) goto no_context; retry: -down_read (&mm->mmap_sem); +mmap_read_lock (mm); }else {/* * The above down_read_trylock() might have succeeded in which
@@ -504,7 +504,7 @@ static int __kprobes do_page_fault(unsigned long addr, unsigned int esr,might_sleep ();#ifdef CONFIG_DEBUG_VM if (!user_mode (regs) && !search_exception_tables (regs->pc)) { -up_read (&mm->mmap_sem); +mmap_read_unlock (mm); goto no_context; }#endif
@@ -536,7 +536,7 @@ static int __kprobes do_page_fault(unsigned long addr, unsigned int esr, goto retry; } } -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);/* * Handle the "normal" (no error) case first.
arch/csky/kernel/vdso.c +2 -2
@@ -50,7 +50,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)unsigned long addr;struct mm_struct *mm = current->mm; -down_write (&mm->mmap_sem); +mmap_write_lock (mm); addr =get_unmapped_area (NULL ,STACK_TOP ,PAGE_SIZE ,0 ,0 );if (IS_ERR_VALUE (addr)) {
@@ -70,7 +70,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp) mm->context.vdso = (void *)addr; up_fail: -up_write (&mm->mmap_sem); +mmap_write_unlock (mm);return ret; }
arch/csky/mm/fault.c +4 -4
@@ -116,7 +116,7 @@ asmlinkage void do_page_fault(struct pt_regs *regs, unsigned long write,if (in_atomic () || !mm) goto bad_area_nosemaphore; -down_read (&mm->mmap_sem); +mmap_read_lock (mm); vma =find_vma (mm, address);if (!vma) goto bad_area;
@@ -166,7 +166,7 @@ asmlinkage void do_page_fault(struct pt_regs *regs, unsigned long write, address); } -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);return ;/*
@@ -174,7 +174,7 @@ asmlinkage void do_page_fault(struct pt_regs *regs, unsigned long write,* Fix it, but check if it's kernel or user first.. */ bad_area: -up_read (&mm->mmap_sem); +mmap_read_unlock (mm); bad_area_nosemaphore:/* User mode accesses just cause a SIGSEGV */
@@ -206,7 +206,7 @@ asmlinkage void do_page_fault(struct pt_regs *regs, unsigned long write,return ; do_sigbus: -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);/* Kernel mode? Handle exceptions or die */ if (!user_mode (regs))
arch/hexagon/kernel/vdso.c +2 -2
@@ -52,7 +52,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)unsigned long vdso_base;struct mm_struct *mm = current->mm; -if (down_write_killable (&mm->mmap_sem)) +if (mmap_write_lock_killable (mm))return -EINTR ;/* Try to get it loaded right near ld.so/glibc. */
@@ -76,7 +76,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp) mm->context.vdso = (void *)vdso_base; up_fail: -up_write (&mm->mmap_sem); +mmap_write_unlock (mm);return ret; }
arch/hexagon/mm/vm_fault.c +4 -4
@@ -55,7 +55,7 @@ void do_page_fault(unsigned long address, long cause, struct pt_regs *regs)if (user_mode (regs)) flags |=FAULT_FLAG_USER ; retry: -down_read (&mm->mmap_sem); +mmap_read_lock (mm); vma =find_vma (mm, address);if (!vma) goto bad_area;
@@ -108,11 +108,11 @@ void do_page_fault(unsigned long address, long cause, struct pt_regs *regs) } } -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);return ; } -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);/* Handle copyin/out exception cases */ if (!user_mode (regs))
@@ -139,7 +139,7 @@ void do_page_fault(unsigned long address, long cause, struct pt_regs *regs)return ; bad_area: -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);if (user_mode (regs)) {force_sig_fault (SIGSEGV , si_code, (void __user *)address);
arch/ia64/kernel/perfmon.c +4 -4
@@ -2258,13 +2258,13 @@ pfm_smpl_buffer_alloc(struct task_struct *task, struct file *filp, pfm_context_t* now we atomically find some area in the address space and * remap the buffer in it. */ -down_write (&task->mm->mmap_sem); +mmap_write_lock (task->mm);/* find some free area in address space, must have mmap sem held */ vma->vm_start =get_unmapped_area (NULL ,0 , size,0 ,MAP_PRIVATE |MAP_ANONYMOUS );if (IS_ERR_VALUE (vma->vm_start)) {DPRINT (("Cannot find unmapped area for size %ld\n" , size)); -up_write (&task->mm->mmap_sem); +mmap_write_unlock (task->mm); goto error; } vma->vm_end = vma->vm_start + size;
@@ -2275,7 +2275,7 @@ pfm_smpl_buffer_alloc(struct task_struct *task, struct file *filp, pfm_context_t/* can only be applied to current task, need to have the mm semaphore held when called */ if (pfm_remap_buffer (vma, (unsigned long )smpl_buf, vma->vm_start, size)) {DPRINT (("Can't remap buffer\n" )); -up_write (&task->mm->mmap_sem); +mmap_write_unlock (task->mm); goto error; }
@@ -2286,7 +2286,7 @@ pfm_smpl_buffer_alloc(struct task_struct *task, struct file *filp, pfm_context_tinsert_vm_struct (mm, vma);vm_stat_account (vma->vm_mm, vma->vm_flags,vma_pages (vma)); -up_write (&task->mm->mmap_sem); +mmap_write_unlock (task->mm);/* * keep track of user level virtual address
arch/ia64/mm/fault.c +4 -4
@@ -102,7 +102,7 @@ ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *reif (mask &VM_WRITE ) flags |=FAULT_FLAG_WRITE ; retry: -down_read (&mm->mmap_sem); +mmap_read_lock (mm); vma =find_vma_prev (mm, address, &prev_vma);if (!vma && !prev_vma )
@@ -179,7 +179,7 @@ ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *re } } -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);return ; check_expansion:
@@ -210,7 +210,7 @@ ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *re goto good_area; bad_area: -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);#ifdef CONFIG_VIRTUAL_MEM_MAP bad_area_no_up:#endif
@@ -276,7 +276,7 @@ ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *rereturn ; out_of_memory: -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);if (!user_mode (regs)) goto no_context;pagefault_out_of_memory ();
arch/ia64/mm/init.c +6 -6
@@ -118,13 +118,13 @@ ia64_init_addr_space (void) vma->vm_end = vma->vm_start +PAGE_SIZE ; vma->vm_flags =VM_DATA_DEFAULT_FLAGS |VM_GROWSUP |VM_ACCOUNT ; vma->vm_page_prot =vm_get_page_prot (vma->vm_flags); -down_write (¤t->mm->mmap_sem); +mmap_write_lock (current->mm);if (insert_vm_struct (current->mm, vma)) { -up_write (¤t->mm->mmap_sem); +mmap_write_unlock (current->mm);vm_area_free (vma);return ; } -up_write (¤t->mm->mmap_sem); +mmap_write_unlock (current->mm); }/* map NaT-page at address zero to speed up speculative dereferencing of NULL: */
@@ -136,13 +136,13 @@ ia64_init_addr_space (void) vma->vm_page_prot =__pgprot (pgprot_val (PAGE_READONLY ) | _PAGE_MA_NAT); vma->vm_flags =VM_READ |VM_MAYREAD |VM_IO |VM_DONTEXPAND |VM_DONTDUMP ; -down_write (¤t->mm->mmap_sem); +mmap_write_lock (current->mm);if (insert_vm_struct (current->mm, vma)) { -up_write (¤t->mm->mmap_sem); +mmap_write_unlock (current->mm);vm_area_free (vma);return ; } -up_write (¤t->mm->mmap_sem); +mmap_write_unlock (current->mm); } } }
arch/m68k/kernel/sys_m68k.c +7 -7
@@ -399,7 +399,7 @@ sys_cacheflush (unsigned long addr, int scope, int cache, unsigned long len)* Verify that the specified address region actually belongs * to this process. */ -down_read (¤t->mm->mmap_sem); +mmap_read_lock (current->mm); vma =find_vma (current->mm, addr);if (!vma || addr < vma->vm_start || addr + len > vma->vm_end) goto out_unlock;
@@ -450,7 +450,7 @@ sys_cacheflush (unsigned long addr, int scope, int cache, unsigned long len) } } out_unlock: -up_read (¤t->mm->mmap_sem); +mmap_read_unlock (current->mm); out:return ret; }
@@ -472,7 +472,7 @@ sys_atomic_cmpxchg_32(unsigned long newval, int oldval, int d3, int d4, int d5,spinlock_t *ptl;unsigned long mem_value; -down_read (&mm->mmap_sem); +mmap_read_lock (mm); pgd =pgd_offset (mm, (unsigned long )mem);if (!pgd_present (*pgd)) goto bad_access;
@@ -501,11 +501,11 @@ sys_atomic_cmpxchg_32(unsigned long newval, int oldval, int d3, int d4, int d5,__put_user (newval, mem);pte_unmap_unlock (pte, ptl); -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);return mem_value; bad_access: -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);/* This is not necessarily a bad access, we can get here if a memory we're trying to write to should be copied-on-write. Make the kernel do the necessary page stuff, then re-iterate.
@@ -545,13 +545,13 @@ sys_atomic_cmpxchg_32(unsigned long newval, int oldval, int d3, int d4, int d5,struct mm_struct *mm = current->mm;unsigned long mem_value; -down_read (&mm->mmap_sem); +mmap_read_lock (mm); mem_value = *mem;if (mem_value == oldval) *mem = newval; -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);return mem_value; }
arch/m68k/mm/fault.c +4 -4
@@ -86,7 +86,7 @@ int do_page_fault(struct pt_regs *regs, unsigned long address,if (user_mode (regs)) flags |=FAULT_FLAG_USER ; retry: -down_read (&mm->mmap_sem); +mmap_read_lock (mm); vma =find_vma (mm, address);if (!vma)
@@ -177,7 +177,7 @@ int do_page_fault(struct pt_regs *regs, unsigned long address, } } -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);return 0 ;/*
@@ -185,7 +185,7 @@ int do_page_fault(struct pt_regs *regs, unsigned long address,* us unable to handle the page fault gracefully. */ out_of_memory: -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);if (!user_mode (regs)) goto no_context;pagefault_out_of_memory ();
@@ -214,6 +214,6 @@ int do_page_fault(struct pt_regs *regs, unsigned long address, current->thread.faddr = address; send_sig: -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);return send_fault_sig (regs); }
arch/microblaze/mm/fault.c +6 -6
@@ -137,12 +137,12 @@ void do_page_fault(struct pt_regs *regs, unsigned long address,* source. If this is invalid we can skip the address space check, * thus avoiding the deadlock. */ -if (unlikely (!down_read_trylock (&mm->mmap_sem))) { +if (unlikely (!mmap_read_trylock (mm))) {if (kernel_mode (regs) && !search_exception_tables (regs->pc)) goto bad_area_nosemaphore; retry: -down_read (&mm->mmap_sem); +mmap_read_lock (mm); } vma =find_vma (mm, address);
@@ -249,7 +249,7 @@ void do_page_fault(struct pt_regs *regs, unsigned long address, } } -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);/* * keep track of tlb+htab misses that are good addrs but
@@ -260,7 +260,7 @@ void do_page_fault(struct pt_regs *regs, unsigned long address,return ; bad_area: -up_read (&mm->mmap_sem); +mmap_read_unlock (mm); bad_area_nosemaphore: pte_errors++;
@@ -279,7 +279,7 @@ void do_page_fault(struct pt_regs *regs, unsigned long address,* us unable to handle the page fault gracefully. */ out_of_memory: -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);if (!user_mode (regs))bad_page_fault (regs, address,SIGKILL );else
@@ -287,7 +287,7 @@ void do_page_fault(struct pt_regs *regs, unsigned long address,return ; do_sigbus: -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);if (user_mode (regs)) {force_sig_fault (SIGBUS ,BUS_ADRERR , (void __user *)address);return ;
arch/mips/kernel/traps.c +2 -2
@@ -749,13 +749,13 @@ int process_fpemu_return(int sig, void __user *fault_addr, unsigned long fcr31)return 1 ;case SIGSEGV : -down_read (¤t->mm->mmap_sem); +mmap_read_lock (current->mm); vma =find_vma (current->mm, (unsigned long )fault_addr);if (vma && (vma->vm_start <= (unsigned long )fault_addr)) si_code =SEGV_ACCERR ;else si_code =SEGV_MAPERR ; -up_read (¤t->mm->mmap_sem); +mmap_read_unlock (current->mm);force_sig_fault (SIGSEGV , si_code, fault_addr);return 1 ;
arch/mips/kernel/vdso.c +2 -2
@@ -92,7 +92,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)struct vm_area_struct *vma;int ret; -if (down_write_killable (&mm->mmap_sem)) +if (mmap_write_lock_killable (mm))return -EINTR ;/* Map delay slot emulation page */
@@ -183,6 +183,6 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp) ret =0 ; out: -up_write (&mm->mmap_sem); +mmap_write_unlock (mm);return ret; }
arch/nds32/kernel/vdso.c +3 -3
@@ -130,7 +130,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp) vdso_mapping_len += L1_cache_info[DCACHE ].aliasing_num -1 ;#endif -if (down_write_killable (&mm->mmap_sem)) +if (mmap_write_lock_killable (mm))return -EINTR ; addr =vdso_random_addr (vdso_mapping_len);
@@ -185,12 +185,12 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp) goto up_fail; } -up_write (&mm->mmap_sem); +mmap_write_unlock (mm);return 0 ; up_fail: mm->context.vdso =NULL ; -up_write (&mm->mmap_sem); +mmap_write_unlock (mm);return ret; }
arch/nds32/mm/fault.c +6 -6
@@ -127,12 +127,12 @@ void do_page_fault(unsigned long entry, unsigned long addr,* validly references user space from well defined areas of the code, * we can bug out early if this is from code which shouldn't. */ -if (unlikely (!down_read_trylock (&mm->mmap_sem))) { +if (unlikely (!mmap_read_trylock (mm))) {if (!user_mode (regs) && !search_exception_tables (instruction_pointer (regs))) goto no_context; retry: -down_read (&mm->mmap_sem); +mmap_read_lock (mm); }else {/* * The above down_read_trylock() might have succeeded in which
@@ -257,7 +257,7 @@ void do_page_fault(unsigned long entry, unsigned long addr, } } -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);return ;/*
@@ -265,7 +265,7 @@ void do_page_fault(unsigned long entry, unsigned long addr,* Fix it, but check if it's kernel or user first.. */ bad_area: -up_read (&mm->mmap_sem); +mmap_read_unlock (mm); bad_area_nosemaphore:
@@ -325,14 +325,14 @@ void do_page_fault(unsigned long entry, unsigned long addr,*/ out_of_memory: -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);if (!user_mode (regs)) goto no_context;pagefault_out_of_memory ();return ; do_sigbus: -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);/* Kernel mode? Handle exceptions or die */ if (!user_mode (regs))
arch/nios2/mm/fault.c +6 -6
@@ -83,11 +83,11 @@ asmlinkage void do_page_fault(struct pt_regs *regs, unsigned long cause,if (user_mode (regs)) flags |=FAULT_FLAG_USER ; -if (!down_read_trylock (&mm->mmap_sem)) { +if (!mmap_read_trylock (mm)) {if (!user_mode (regs) && !search_exception_tables (regs->ea)) goto bad_area_nosemaphore; retry: -down_read (&mm->mmap_sem); +mmap_read_lock (mm); } vma =find_vma (mm, address);
@@ -172,7 +172,7 @@ asmlinkage void do_page_fault(struct pt_regs *regs, unsigned long cause, } } -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);return ;/*
@@ -180,7 +180,7 @@ asmlinkage void do_page_fault(struct pt_regs *regs, unsigned long cause,* Fix it, but check if it's kernel or user first.. */ bad_area: -up_read (&mm->mmap_sem); +mmap_read_unlock (mm); bad_area_nosemaphore:/* User mode accesses just cause a SIGSEGV */
@@ -218,14 +218,14 @@ asmlinkage void do_page_fault(struct pt_regs *regs, unsigned long cause,* us unable to handle the page fault gracefully. */ out_of_memory: -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);if (!user_mode (regs)) goto no_context;pagefault_out_of_memory ();return ; do_sigbus: -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);/* Kernel mode? Handle exceptions or die */ if (!user_mode (regs))
arch/nios2/mm/init.c +2 -2
@@ -112,14 +112,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)struct mm_struct *mm = current->mm;int ret; -down_write (&mm->mmap_sem); +mmap_write_lock (mm);/* Map kuser helpers to user space address */ ret =install_special_mapping (mm,KUSER_BASE ,KUSER_SIZE ,VM_READ |VM_EXEC |VM_MAYREAD |VM_MAYEXEC , kuser_page); -up_write (&mm->mmap_sem); +mmap_write_unlock (mm);return ret; }
arch/openrisc/mm/fault.c +5 -5
@@ -104,7 +104,7 @@ asmlinkage void do_page_fault(struct pt_regs *regs, unsigned long address, goto no_context; retry: -down_read (&mm->mmap_sem); +mmap_read_lock (mm); vma =find_vma (mm, address);if (!vma)
@@ -193,7 +193,7 @@ asmlinkage void do_page_fault(struct pt_regs *regs, unsigned long address, } } -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);return ;/*
@@ -202,7 +202,7 @@ asmlinkage void do_page_fault(struct pt_regs *regs, unsigned long address,*/ bad_area: -up_read (&mm->mmap_sem); +mmap_read_unlock (mm); bad_area_nosemaphore:
@@ -261,14 +261,14 @@ asmlinkage void do_page_fault(struct pt_regs *regs, unsigned long address, __asm__ __volatile__("l.nop 42" ); __asm__ __volatile__("l.nop 1" ); -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);if (!user_mode (regs)) goto no_context;pagefault_out_of_memory ();return ; do_sigbus: -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);/* * Send a sigbus, regardless of whether we were in kernel
arch/parisc/kernel/traps.c +3 -3
@@ -717,7 +717,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)if (user_mode (regs)) {struct vm_area_struct *vma; -down_read (¤t->mm->mmap_sem); +mmap_read_lock (current->mm); vma =find_vma (current->mm,regs->iaoq[0 ]);if (vma && (regs->iaoq[0 ] >= vma->vm_start) && (vma->vm_flags &VM_EXEC )) {
@@ -725,10 +725,10 @@ void notrace handle_interruption(int code, struct pt_regs *regs) fault_address = regs->iaoq[0 ]; fault_space = regs->iasq[0 ]; -up_read (¤t->mm->mmap_sem); +mmap_read_unlock (current->mm);break ;/* call do_page_fault() */ } -up_read (¤t->mm->mmap_sem); +mmap_read_unlock (current->mm); }/* Fall Through */ case 27 :
arch/parisc/mm/fault.c +4 -4
@@ -282,7 +282,7 @@ void do_page_fault(struct pt_regs *regs, unsigned long code,if (acc_type &VM_WRITE ) flags |=FAULT_FLAG_WRITE ; retry: -down_read (&mm->mmap_sem); +mmap_read_lock (mm); vma =find_vma_prev (mm, address, &prev_vma);if (!vma || address < vma->vm_start) goto check_expansion;
@@ -339,7 +339,7 @@ void do_page_fault(struct pt_regs *regs, unsigned long code, goto retry; } } -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);return ; check_expansion:
@@ -351,7 +351,7 @@ void do_page_fault(struct pt_regs *regs, unsigned long code,* Something tried to access memory that isn't in our memory map.. */ bad_area: -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);if (user_mode (regs)) {int signo, si_code;
@@ -423,7 +423,7 @@ void do_page_fault(struct pt_regs *regs, unsigned long code,parisc_terminate ("Bad Address (null pointer deref?)" , regs, code, address); out_of_memory: -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);if (!user_mode (regs)) goto no_context;pagefault_out_of_memory ();
arch/powerpc/kernel/vdso.c +3 -3
@@ -171,7 +171,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)* and end up putting it elsewhere. * Add enough to the size so that the result can be aligned. */ -if (down_write_killable (&mm->mmap_sem)) +if (mmap_write_lock_killable (mm))return -EINTR ; vdso_base = get_unmapped_area(NULL, vdso_base, (vdso_pages << PAGE_SHIFT) +
@@ -211,11 +211,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp) goto fail_mmapsem; } -up_write (&mm->mmap_sem); +mmap_write_unlock (mm);return 0 ; fail_mmapsem: -up_write (&mm->mmap_sem); +mmap_write_unlock (mm);return rc; }
arch/powerpc/kvm/book3s_64_mmu_hv.c +2 -2
@@ -582,7 +582,7 @@ int kvmppc_book3s_hv_page_fault(struct kvm_run *run, struct kvm_vcpu *vcpu, npages =get_user_pages_fast (hva,1 , writing ?FOLL_WRITE :0 , pages);if (npages <1 ) {/* Check if it's an I/O mapping */ -down_read (&mm->mmap_sem); +mmap_read_lock (mm); vma =find_vma (mm, hva);if (vma && vma->vm_start <= hva && hva + psize <= vma->vm_end && (vma->vm_flags &VM_PFNMAP )) {
@@ -592,7 +592,7 @@ int kvmppc_book3s_hv_page_fault(struct kvm_run *run, struct kvm_vcpu *vcpu, is_ci =pte_ci (__pte ((pgprot_val (vma->vm_page_prot)))); write_ok = vma->vm_flags &VM_WRITE ; } -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);if (!pfn) goto out_put; }else {
arch/powerpc/kvm/book3s_hv.c +3 -3
@@ -4630,14 +4630,14 @@ static int kvmppc_hv_setup_htab_rma(struct kvm_vcpu *vcpu)/* Look up the VMA for the start of this memory slot */ hva = memslot->userspace_addr; -down_read (&kvm->mm->mmap_sem); +mmap_read_lock (kvm->mm); vma =find_vma (kvm->mm, hva);if (!vma || vma->vm_start > hva || (vma->vm_flags &VM_IO )) goto up_out; psize =vma_kernel_pagesize (vma); -up_read (&kvm->mm->mmap_sem); +mmap_read_unlock (kvm->mm);/* We can handle 4k, 64k or 16M pages in the VRMA */ if (psize >=0x1000000 )
@@ -4670,7 +4670,7 @@ static int kvmppc_hv_setup_htab_rma(struct kvm_vcpu *vcpu)return err; up_out: -up_read (&kvm->mm->mmap_sem); +mmap_read_unlock (kvm->mm); goto out_srcu; }
arch/powerpc/kvm/book3s_hv_uvmem.c +6 -6
@@ -394,7 +394,7 @@ kvmppc_svm_page_in(struct vm_area_struct *vma, unsigned long start,*/ ret =ksm_madvise (vma, vma->vm_start, vma->vm_end,MADV_UNMERGEABLE , &vma->vm_flags); -downgrade_write (&kvm->mm->mmap_sem); +mmap_downgrade_write_lock (kvm->mm); *downgrade = true;if (ret)return ret;
@@ -511,7 +511,7 @@ kvmppc_h_svm_page_in(struct kvm *kvm, unsigned long gpa, ret =H_PARAMETER ; srcu_idx =srcu_read_lock (&kvm->srcu); -down_write (&kvm->mm->mmap_sem); +mmap_write_lock (kvm->mm); start =gfn_to_hva (kvm, gfn);if (kvm_is_error_hva (start))
@@ -534,9 +534,9 @@ kvmppc_h_svm_page_in(struct kvm *kvm, unsigned long gpa,mutex_unlock (&kvm->arch.uvmem_lock); out:if (downgrade) -up_read (&kvm->mm->mmap_sem); +mmap_read_unlock (kvm->mm);else -up_write (&kvm->mm->mmap_sem); +mmap_write_unlock (kvm->mm);srcu_read_unlock (&kvm->srcu, srcu_idx);return ret; }
@@ -688,7 +688,7 @@ kvmppc_h_svm_page_out(struct kvm *kvm, unsigned long gpa, ret =H_PARAMETER ; srcu_idx =srcu_read_lock (&kvm->srcu); -down_read (&kvm->mm->mmap_sem); +mmap_read_lock (kvm->mm); start =gfn_to_hva (kvm, gfn);if (kvm_is_error_hva (start)) goto out;
@@ -701,7 +701,7 @@ kvmppc_h_svm_page_out(struct kvm *kvm, unsigned long gpa,if (!kvmppc_svm_page_out (vma, start, end, page_shift, kvm, gpa)) ret =H_SUCCESS ; out: -up_read (&kvm->mm->mmap_sem); +mmap_read_unlock (kvm->mm);srcu_read_unlock (&kvm->srcu, srcu_idx);return ret; }
arch/powerpc/kvm/e500_mmu_host.c +2 -2
@@ -355,7 +355,7 @@ static inline int kvmppc_e500_shadow_map(struct kvmppc_vcpu_e500 *vcpu_e500,if (tlbsel ==1 ) {struct vm_area_struct *vma; -down_read (&kvm->mm->mmap_sem); +mmap_read_lock (kvm->mm); vma =find_vma (kvm->mm, hva); if (vma && hva >= vma->vm_start &&
@@ -441,7 +441,7 @@ static inline int kvmppc_e500_shadow_map(struct kvmppc_vcpu_e500 *vcpu_e500, tsize =max (BOOK3E_PAGESZ_4K , tsize & ~1 ); } -up_read (&kvm->mm->mmap_sem); +mmap_read_unlock (kvm->mm); }if (likely (!pfnmap)) {
arch/powerpc/mm/book3s64/iommu_api.c +2 -2
@@ -96,7 +96,7 @@ static long mm_iommu_do_alloc(struct mm_struct *mm, unsigned long ua, goto unlock_exit; } -down_read (&mm->mmap_sem); +mmap_read_lock (mm); chunk = (1UL << (PAGE_SHIFT +MAX_ORDER -1 )) /sizeof (struct vm_area_struct *); chunk =min (chunk, entries);
@@ -114,7 +114,7 @@ static long mm_iommu_do_alloc(struct mm_struct *mm, unsigned long ua, pinned += ret;break ; } -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);if (pinned != entries) {if (!ret) ret = -EFAULT ;
arch/powerpc/mm/book3s64/subpage_prot.c +6 -6
@@ -92,7 +92,7 @@ static void subpage_prot_clear(unsigned long addr, unsigned long len)size_t nw;unsigned long next, limit; -down_write (&mm->mmap_sem); +mmap_write_lock (mm); spt =mm_ctx_subpage_prot (&mm->context);if (!spt)
@@ -127,7 +127,7 @@ static void subpage_prot_clear(unsigned long addr, unsigned long len) } err_out: -up_write (&mm->mmap_sem); +mmap_write_unlock (mm); }#ifdef CONFIG_TRANSPARENT_HUGEPAGE
@@ -217,7 +217,7 @@ SYSCALL_DEFINE3(subpage_prot, unsigned long, addr,if (!access_ok (map, (len >>PAGE_SHIFT ) *sizeof (u32)))return -EFAULT ; -down_write (&mm->mmap_sem); +mmap_write_lock (mm); spt =mm_ctx_subpage_prot (&mm->context);if (!spt) {
@@ -267,11 +267,11 @@ SYSCALL_DEFINE3(subpage_prot, unsigned long, addr,if (addr + (nw <<PAGE_SHIFT ) > next) nw = (next - addr) >>PAGE_SHIFT ; -up_write (&mm->mmap_sem); +mmap_write_unlock (mm);if (__copy_from_user (spp, map, nw *sizeof (u32)))return -EFAULT ; map += nw; -down_write (&mm->mmap_sem); +mmap_write_lock (mm);/* now flush any existing HPTEs for the range */ hpte_flush_range (mm, addr, nw);
@@ -280,6 +280,6 @@ SYSCALL_DEFINE3(subpage_prot, unsigned long, addr, spt->maxaddr = limit; err =0 ; out: -up_write (&mm->mmap_sem); +mmap_write_unlock (mm);return err; }
arch/powerpc/mm/copro_fault.c +2 -2
@@ -33,7 +33,7 @@ int copro_handle_mm_fault(struct mm_struct *mm, unsigned long ea,if (mm->pgd ==NULL )return -EFAULT ; -down_read (&mm->mmap_sem); +mmap_read_lock (mm); ret = -EFAULT ; vma =find_vma (mm, ea);if (!vma)
@@ -82,7 +82,7 @@ int copro_handle_mm_fault(struct mm_struct *mm, unsigned long ea, current->min_flt++; out_unlock: -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);return ret; }EXPORT_SYMBOL_GPL (copro_handle_mm_fault);
arch/powerpc/mm/fault.c +6 -6
@@ -108,7 +108,7 @@ static int __bad_area(struct pt_regs *regs, unsigned long address, int si_code)* Something tried to access memory that isn't in our memory map.. * Fix it, but check if it's kernel or user first.. */ -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);return __bad_area_nosemaphore (regs, address, si_code); }
@@ -514,12 +514,12 @@ static int __do_page_fault(struct pt_regs *regs, unsigned long address,* source. If this is invalid we can skip the address space check, * thus avoiding the deadlock. */ -if (unlikely (!down_read_trylock (&mm->mmap_sem))) { +if (unlikely (!mmap_read_trylock (mm))) {if (!is_user && !search_exception_tables (regs->nip))return bad_area_nosemaphore (regs, address); retry: -down_read (&mm->mmap_sem); +mmap_read_lock (mm); }else {/* * The above down_read_trylock() might have succeeded in
@@ -543,7 +543,7 @@ static int __do_page_fault(struct pt_regs *regs, unsigned long address,if (!must_retry)return bad_area (regs, address); -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);if (fault_in_pages_readable ((const char __user *)regs->nip,sizeof (unsigned int )))return bad_area_nosemaphore (regs, address);
@@ -575,7 +575,7 @@ static int __do_page_fault(struct pt_regs *regs, unsigned long address,int pkey =vma_pkey (vma); -up_read (&mm->mmap_sem); +mmap_read_unlock (mm); return bad_key_fault_exception(regs, address, pkey); }#endif /* CONFIG_PPC_MEM_KEYS */
@@ -606,7 +606,7 @@ static int __do_page_fault(struct pt_regs *regs, unsigned long address,return is_user ?0 :SIGBUS ; } -up_read (¤t->mm->mmap_sem); +mmap_read_unlock (current->mm);if (unlikely (fault &VM_FAULT_ERROR ))return mm_fault_error (regs, address, fault);
arch/powerpc/oprofile/cell/spu_task_sync.c +3 -3
@@ -332,7 +332,7 @@ get_exec_dcookie_and_offset(struct spu *spu, unsigned int *offsetp,fput (exe_file); } -down_read (&mm->mmap_sem); +mmap_read_lock (mm);for (vma = mm->mmap; vma; vma = vma->vm_next) {if (vma->vm_start > spu_ref || vma->vm_end <= spu_ref)continue ;
@@ -349,13 +349,13 @@ get_exec_dcookie_and_offset(struct spu *spu, unsigned int *offsetp, *spu_bin_dcookie =fast_get_dcookie (&vma->vm_file->f_path);pr_debug ("got dcookie for %pD\n" , vma->vm_file); -up_read (&mm->mmap_sem); +mmap_read_unlock (mm); out:return app_cookie; fail_no_image_cookie: -up_read (&mm->mmap_sem); +mmap_read_unlock (mm); printk(KERN_ERR "SPU_PROF: " "%s, line %d: Cannot find dcookie for SPU binary\n",
arch/powerpc/platforms/cell/spufs/file.c +2 -2
@@ -336,11 +336,11 @@ static vm_fault_t spufs_ps_fault(struct vm_fault *vmf, goto refault;if (ctx->state ==SPU_STATE_SAVED ) { -up_read (¤t->mm->mmap_sem); +mmap_read_unlock (current->mm);spu_context_nospu_trace (spufs_ps_fault__sleep, ctx); err =spufs_wait (ctx->run_wq, ctx->state ==SPU_STATE_RUNNABLE );spu_context_trace (spufs_ps_fault__wake, ctx, ctx->spu); -down_read (¤t->mm->mmap_sem); +mmap_read_lock (current->mm); }else { area = ctx->spu->problem_phys + ps_offs; ret = vmf_insert_pfn(vmf->vma, vmf->address,
arch/riscv/kernel/vdso.c +2 -2
@@ -61,7 +61,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, vdso_len = (vdso_pages +1 ) <<PAGE_SHIFT ; -down_write (&mm->mmap_sem); +mmap_write_lock (mm); vdso_base =get_unmapped_area (NULL ,0 , vdso_len,0 ,0 );if (IS_ERR_VALUE (vdso_base)) { ret = vdso_base;
@@ -83,7 +83,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, mm->context.vdso =NULL ; end: -up_write (&mm->mmap_sem); +mmap_write_unlock (mm);return ret; }
arch/riscv/mm/fault.c +5 -5
@@ -69,7 +69,7 @@ asmlinkage void do_page_fault(struct pt_regs *regs)perf_sw_event (PERF_COUNT_SW_PAGE_FAULTS ,1 , regs, addr); retry: -down_read (&mm->mmap_sem); +mmap_read_lock (mm); vma =find_vma (mm, addr);if (unlikely (!vma)) goto bad_area;
@@ -160,7 +160,7 @@ asmlinkage void do_page_fault(struct pt_regs *regs) } } -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);return ;/*
@@ -168,7 +168,7 @@ asmlinkage void do_page_fault(struct pt_regs *regs)* Fix it, but check if it's kernel or user first. */ bad_area: -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);/* User mode accesses just cause a SIGSEGV */ if (user_mode (regs)) {do_trap (regs,SIGSEGV , code, addr);
@@ -196,14 +196,14 @@ asmlinkage void do_page_fault(struct pt_regs *regs)* (which will retry the fault, or kill us if we got oom-killed). */ out_of_memory: -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);if (!user_mode (regs)) goto no_context;pagefault_out_of_memory ();return ; do_sigbus: -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);/* Kernel mode? Handle exceptions or die */ if (!user_mode (regs)) goto no_context;
arch/s390/kernel/vdso.c +2 -2
@@ -208,7 +208,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)* it at vdso_base which is the "natural" base for it, but we might * fail and end up putting it elsewhere. */ -if (down_write_killable (&mm->mmap_sem)) +if (mmap_write_lock_killable (mm))return -EINTR ; vdso_base =get_unmapped_area (NULL ,0 , vdso_pages <<PAGE_SHIFT ,0 ,0 );if (IS_ERR_VALUE (vdso_base)) {
@@ -239,7 +239,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp) rc =0 ; out_up: -up_write (&mm->mmap_sem); +mmap_write_unlock (mm);return rc; }
arch/s390/kvm/gaccess.c +2 -2
@@ -1170,7 +1170,7 @@ int kvm_s390_shadow_fault(struct kvm_vcpu *vcpu, struct gmap *sg,int dat_protection, fake;int rc; -down_read (&sg->mm->mmap_sem); +mmap_read_lock (sg->mm);/* * We don't want any guest-2 tables to change - so the parent * tables/pointers we read stay valid - unshadowing is however
@@ -1199,6 +1199,6 @@ int kvm_s390_shadow_fault(struct kvm_vcpu *vcpu, struct gmap *sg,if (!rc) rc =gmap_shadow_page (sg, saddr,__pte (pte.val));ipte_unlock (vcpu); -up_read (&sg->mm->mmap_sem); +mmap_read_unlock (sg->mm);return rc; }
arch/s390/kvm/kvm-s390.c +12 -12
@@ -754,9 +754,9 @@ int kvm_vm_ioctl_enable_cap(struct kvm *kvm, struct kvm_enable_cap *cap) r = -EINVAL ; else { r =0 ; -down_write (&kvm->mm->mmap_sem); +mmap_write_lock (kvm->mm); kvm->mm->context.allow_gmap_hpage_1m =1 ; -up_write (&kvm->mm->mmap_sem); +mmap_write_unlock (kvm->mm);/* * We might have to create fake 4k page * tables. To avoid that the hardware works on
@@ -1806,7 +1806,7 @@ static long kvm_s390_get_skeys(struct kvm *kvm, struct kvm_s390_skeys *args)if (!keys)return -ENOMEM ; -down_read (¤t->mm->mmap_sem); +mmap_read_lock (current->mm); srcu_idx =srcu_read_lock (&kvm->srcu);for (i =0 ; i < args->count; i++) { hva =gfn_to_hva (kvm, args->start_gfn + i);
@@ -1820,7 +1820,7 @@ static long kvm_s390_get_skeys(struct kvm *kvm, struct kvm_s390_skeys *args)break ; }srcu_read_unlock (&kvm->srcu, srcu_idx); -up_read (¤t->mm->mmap_sem); +mmap_read_unlock (current->mm);if (!r) { r = copy_to_user((uint8_t __user *)args->skeydata_addr, keys,
@@ -1864,7 +1864,7 @@ static long kvm_s390_set_skeys(struct kvm *kvm, struct kvm_s390_skeys *args) goto out; i =0 ; -down_read (¤t->mm->mmap_sem); +mmap_read_lock (current->mm); srcu_idx =srcu_read_lock (&kvm->srcu);while (i < args->count) { unlocked = false;
@@ -1891,7 +1891,7 @@ static long kvm_s390_set_skeys(struct kvm *kvm, struct kvm_s390_skeys *args) i++; }srcu_read_unlock (&kvm->srcu, srcu_idx); -up_read (¤t->mm->mmap_sem); +mmap_read_unlock (current->mm); out:kvfree (keys);return r;
@@ -2074,14 +2074,14 @@ static int kvm_s390_get_cmma_bits(struct kvm *kvm,if (!values)return -ENOMEM ; -down_read (&kvm->mm->mmap_sem); +mmap_read_lock (kvm->mm); srcu_idx =srcu_read_lock (&kvm->srcu);if (peek) ret =kvm_s390_peek_cmma (kvm, args, values, bufsize);else ret =kvm_s390_get_cmma (kvm, args, values, bufsize);srcu_read_unlock (&kvm->srcu, srcu_idx); -up_read (&kvm->mm->mmap_sem); +mmap_read_unlock (kvm->mm);if (kvm->arch.migration_mode) args->remaining =atomic64_read (&kvm->arch.cmma_dirty_pages);
@@ -2131,7 +2131,7 @@ static int kvm_s390_set_cmma_bits(struct kvm *kvm, goto out; } -down_read (&kvm->mm->mmap_sem); +mmap_read_lock (kvm->mm); srcu_idx =srcu_read_lock (&kvm->srcu);for (i =0 ; i < args->count; i++) { hva =gfn_to_hva (kvm, args->start_gfn + i);
@@ -2146,12 +2146,12 @@ static int kvm_s390_set_cmma_bits(struct kvm *kvm,set_pgste_bits (kvm->mm, hva, mask, pgstev); }srcu_read_unlock (&kvm->srcu, srcu_idx); -up_read (&kvm->mm->mmap_sem); +mmap_read_unlock (kvm->mm);if (!kvm->mm->context.uses_cmm) { -down_write (&kvm->mm->mmap_sem); +mmap_write_lock (kvm->mm); kvm->mm->context.uses_cmm =1 ; -up_write (&kvm->mm->mmap_sem); +mmap_write_unlock (kvm->mm); } out:vfree (bits);
arch/s390/kvm/priv.c +16 -16
@@ -270,18 +270,18 @@ static int handle_iske(struct kvm_vcpu *vcpu)return kvm_s390_inject_program_int (vcpu,PGM_ADDRESSING ); retry: unlocked = false; -down_read (¤t->mm->mmap_sem); +mmap_read_lock (current->mm); rc =get_guest_storage_key (current->mm, vmaddr, &key);if (rc) { rc =fixup_user_fault (current, current->mm, vmaddr,FAULT_FLAG_WRITE , &unlocked);if (!rc) { -up_read (¤t->mm->mmap_sem); +mmap_read_unlock (current->mm); goto retry; } } -up_read (¤t->mm->mmap_sem); +mmap_read_unlock (current->mm);if (rc == -EFAULT )return kvm_s390_inject_program_int (vcpu,PGM_ADDRESSING );if (rc <0 )
@@ -317,17 +317,17 @@ static int handle_rrbe(struct kvm_vcpu *vcpu)return kvm_s390_inject_program_int (vcpu,PGM_ADDRESSING ); retry: unlocked = false; -down_read (¤t->mm->mmap_sem); +mmap_read_lock (current->mm); rc =reset_guest_reference_bit (current->mm, vmaddr);if (rc <0 ) { rc =fixup_user_fault (current, current->mm, vmaddr,FAULT_FLAG_WRITE , &unlocked);if (!rc) { -up_read (¤t->mm->mmap_sem); +mmap_read_unlock (current->mm); goto retry; } } -up_read (¤t->mm->mmap_sem); +mmap_read_unlock (current->mm);if (rc == -EFAULT )return kvm_s390_inject_program_int (vcpu,PGM_ADDRESSING );if (rc <0 )
@@ -385,7 +385,7 @@ static int handle_sske(struct kvm_vcpu *vcpu)if (kvm_is_error_hva (vmaddr))return kvm_s390_inject_program_int (vcpu,PGM_ADDRESSING ); -down_read (¤t->mm->mmap_sem); +mmap_read_lock (current->mm); rc =cond_set_guest_storage_key (current->mm, vmaddr, key, &oldkey, m3 &SSKE_NQ , m3 &SSKE_MR , m3 &SSKE_MC );
@@ -395,7 +395,7 @@ static int handle_sske(struct kvm_vcpu *vcpu) FAULT_FLAG_WRITE, &unlocked); rc = !rc ? -EAGAIN : rc; } -up_read (¤t->mm->mmap_sem); +mmap_read_unlock (current->mm);if (rc == -EFAULT )return kvm_s390_inject_program_int (vcpu,PGM_ADDRESSING );if (rc <0 )
@@ -1084,7 +1084,7 @@ static int handle_pfmf(struct kvm_vcpu *vcpu)if (rc)return rc; -down_read (¤t->mm->mmap_sem); +mmap_read_lock (current->mm); rc =cond_set_guest_storage_key (current->mm, vmaddr, key,NULL , nq, mr, mc);if (rc <0 ) {
@@ -1092,7 +1092,7 @@ static int handle_pfmf(struct kvm_vcpu *vcpu) FAULT_FLAG_WRITE, &unlocked); rc = !rc ? -EAGAIN : rc; } -up_read (¤t->mm->mmap_sem); +mmap_read_unlock (current->mm);if (rc == -EFAULT )return kvm_s390_inject_program_int (vcpu,PGM_ADDRESSING );if (rc == -EAGAIN )
@@ -1213,9 +1213,9 @@ static int handle_essa(struct kvm_vcpu *vcpu)* already correct, we do nothing and avoid the lock. */ if (vcpu->kvm->mm->context.uses_cmm ==0 ) { -down_write (&vcpu->kvm->mm->mmap_sem); +mmap_write_lock (vcpu->kvm->mm); vcpu->kvm->mm->context.uses_cmm =1 ; -up_write (&vcpu->kvm->mm->mmap_sem); +mmap_write_unlock (vcpu->kvm->mm); }/* * If we are here, we are supposed to have CMMA enabled in
@@ -1232,11 +1232,11 @@ static int handle_essa(struct kvm_vcpu *vcpu) }else {int srcu_idx; -down_read (&vcpu->kvm->mm->mmap_sem); +mmap_read_lock (vcpu->kvm->mm); srcu_idx =srcu_read_lock (&vcpu->kvm->srcu); i =__do_essa (vcpu, orc);srcu_read_unlock (&vcpu->kvm->srcu, srcu_idx); -up_read (&vcpu->kvm->mm->mmap_sem); +mmap_read_unlock (vcpu->kvm->mm);if (i <0 )return i;/* Account for the possible extra cbrl entry */
@@ -1244,10 +1244,10 @@ static int handle_essa(struct kvm_vcpu *vcpu) } vcpu->arch.sie_block->cbrlo &=PAGE_MASK ;/* reset nceo */ cbrlo =phys_to_virt (vcpu->arch.sie_block->cbrlo); -down_read (&gmap->mm->mmap_sem); +mmap_read_lock (gmap->mm);for (i =0 ; i < entries; ++i)__gmap_zap (gmap, cbrlo[i]); -up_read (&gmap->mm->mmap_sem); +mmap_read_unlock (gmap->mm);return 0 ; }
arch/s390/mm/fault.c +3 -3
@@ -434,7 +434,7 @@ static inline vm_fault_t do_exception(struct pt_regs *regs, int access) flags |=FAULT_FLAG_USER ;if (access ==VM_WRITE || (trans_exc_code & store_indication) ==0x400 ) flags |=FAULT_FLAG_WRITE ; -down_read (&mm->mmap_sem); +mmap_read_lock (mm); gmap =NULL ;if (IS_ENABLED (CONFIG_PGSTE ) && type ==GMAP_FAULT ) {
@@ -519,7 +519,7 @@ static inline vm_fault_t do_exception(struct pt_regs *regs, int access) flags &= ~(FAULT_FLAG_ALLOW_RETRY |FAULT_FLAG_RETRY_NOWAIT ); flags |=FAULT_FLAG_TRIED ; -down_read (&mm->mmap_sem); +mmap_read_lock (mm); goto retry; } }
@@ -537,7 +537,7 @@ static inline vm_fault_t do_exception(struct pt_regs *regs, int access) } fault =0 ; out_up: -up_read (&mm->mmap_sem); +mmap_read_unlock (mm); out:return fault; }
arch/s390/mm/gmap.c +20 -20
@@ -405,10 +405,10 @@ int gmap_unmap_segment(struct gmap *gmap, unsigned long to, unsigned long len)return -EINVAL ; flush =0 ; -down_write (&gmap->mm->mmap_sem); +mmap_write_lock (gmap->mm);for (off =0 ; off < len; off +=PMD_SIZE ) flush |=__gmap_unmap_by_gaddr (gmap, to + off); -up_write (&gmap->mm->mmap_sem); +mmap_write_unlock (gmap->mm);if (flush)gmap_flush_tlb (gmap);return 0 ;
@@ -438,7 +438,7 @@ int gmap_map_segment(struct gmap *gmap, unsigned long from,return -EINVAL ; flush =0 ; -down_write (&gmap->mm->mmap_sem); +mmap_write_lock (gmap->mm);for (off =0 ; off < len; off +=PMD_SIZE ) {/* Remove old translation */ flush |=__gmap_unmap_by_gaddr (gmap, to + off);
@@ -448,7 +448,7 @@ int gmap_map_segment(struct gmap *gmap, unsigned long from, (void *) from + off))break ; } -up_write (&gmap->mm->mmap_sem); +mmap_write_unlock (gmap->mm);if (flush)gmap_flush_tlb (gmap);if (off >= len)
@@ -495,9 +495,9 @@ unsigned long gmap_translate(struct gmap *gmap, unsigned long gaddr) {unsigned long rc; -down_read (&gmap->mm->mmap_sem); +mmap_read_lock (gmap->mm); rc =__gmap_translate (gmap, gaddr); -up_read (&gmap->mm->mmap_sem); +mmap_read_unlock (gmap->mm);return rc; }EXPORT_SYMBOL_GPL (gmap_translate);
@@ -640,7 +640,7 @@ int gmap_fault(struct gmap *gmap, unsigned long gaddr,int rc;bool unlocked; -down_read (&gmap->mm->mmap_sem); +mmap_read_lock (gmap->mm); retry: unlocked = false;
@@ -663,7 +663,7 @@ int gmap_fault(struct gmap *gmap, unsigned long gaddr, rc =__gmap_link (gmap, gaddr, vmaddr); out_up: -up_read (&gmap->mm->mmap_sem); +mmap_read_unlock (gmap->mm);return rc; }EXPORT_SYMBOL_GPL (gmap_fault);
@@ -696,7 +696,7 @@ void gmap_discard(struct gmap *gmap, unsigned long from, unsigned long to)unsigned long gaddr, vmaddr, size;struct vm_area_struct *vma; -down_read (&gmap->mm->mmap_sem); +mmap_read_lock (gmap->mm);for (gaddr = from; gaddr < to; gaddr = (gaddr +PMD_SIZE ) &PMD_MASK ) {/* Find the vm address for the guest address */
@@ -719,7 +719,7 @@ void gmap_discard(struct gmap *gmap, unsigned long from, unsigned long to) size =min (to - gaddr,PMD_SIZE - (gaddr & ~PMD_MASK ));zap_page_range (vma, vmaddr, size); } -up_read (&gmap->mm->mmap_sem); +mmap_read_unlock (gmap->mm); }EXPORT_SYMBOL_GPL (gmap_discard);
@@ -1102,9 +1102,9 @@ int gmap_mprotect_notify(struct gmap *gmap, unsigned long gaddr,return -EINVAL ;if (!MACHINE_HAS_ESOP && prot ==PROT_READ )return -EINVAL ; -down_read (&gmap->mm->mmap_sem); +mmap_read_lock (gmap->mm); rc =gmap_protect_range (gmap, gaddr, len, prot,GMAP_NOTIFY_MPROT ); -up_read (&gmap->mm->mmap_sem); +mmap_read_unlock (gmap->mm);return rc; }EXPORT_SYMBOL_GPL (gmap_mprotect_notify);
@@ -1692,11 +1692,11 @@ struct gmap *gmap_shadow(struct gmap *parent, unsigned long asce, }spin_unlock (&parent->shadow_lock);/* protect after insertion, so it will get properly invalidated */ -down_read (&parent->mm->mmap_sem); +mmap_read_lock (parent->mm); rc =gmap_protect_range (parent, asce & _ASCE_ORIGIN, ((asce & _ASCE_TABLE_LENGTH) +1 ) *PAGE_SIZE ,PROT_READ ,GMAP_NOTIFY_SHADOW ); -up_read (&parent->mm->mmap_sem); +mmap_read_unlock (parent->mm);spin_lock (&parent->shadow_lock); new->initialized = true;if (rc) {
@@ -2538,12 +2538,12 @@ int s390_enable_sie(void)/* Fail if the page tables are 2K */ if (!mm_alloc_pgste (mm))return -EINVAL ; -down_write (&mm->mmap_sem); +mmap_write_lock (mm); mm->context.has_pgste =1 ;/* split thp mappings and disable thp for future mappings */ thp_split_mm (mm);walk_page_range (mm,0 ,TASK_SIZE , &zap_zero_walk_ops,NULL ); -up_write (&mm->mmap_sem); +mmap_write_unlock (mm);return 0 ; }EXPORT_SYMBOL_GPL (s390_enable_sie);
@@ -2596,7 +2596,7 @@ int s390_enable_skey(void)struct vm_area_struct *vma;int rc =0 ; -down_write (&mm->mmap_sem); +mmap_write_lock (mm);if (mm_uses_skeys (mm)) goto out_up;
@@ -2614,7 +2614,7 @@ int s390_enable_skey(void)walk_page_range (mm,0 ,TASK_SIZE , &enable_skey_walk_ops,NULL ); out_up: -up_write (&mm->mmap_sem); +mmap_write_unlock (mm);return rc; }EXPORT_SYMBOL_GPL (s390_enable_skey);
@@ -2635,8 +2635,8 @@ static const struct mm_walk_ops reset_cmma_walk_ops = {void s390_reset_cmma (struct mm_struct *mm) { -down_write (&mm->mmap_sem); +mmap_write_lock (mm);walk_page_range (mm,0 ,TASK_SIZE , &reset_cmma_walk_ops,NULL ); -up_write (&mm->mmap_sem); +mmap_write_unlock (mm); }EXPORT_SYMBOL_GPL (s390_reset_cmma);
arch/s390/pci/pci_mmio.c +2 -2
@@ -18,7 +18,7 @@ static long get_pfn(unsigned long user_addr, unsigned long access,struct vm_area_struct *vma;long ret; -down_read (¤t->mm->mmap_sem); +mmap_read_lock (current->mm); ret = -EINVAL ; vma =find_vma (current->mm, user_addr);if (!vma)
@@ -28,7 +28,7 @@ static long get_pfn(unsigned long user_addr, unsigned long access, goto out; ret =follow_pfn (vma, user_addr, pfn); out: -up_read (¤t->mm->mmap_sem); +mmap_read_unlock (current->mm);return ret; }
arch/sh/kernel/sys_sh.c +3 -3
@@ -69,10 +69,10 @@ asmlinkage int sys_cacheflush(unsigned long addr, unsigned long len, int op)if (addr + len < addr)return -EFAULT ; -down_read (¤t->mm->mmap_sem); +mmap_read_lock (current->mm); vma =find_vma (current->mm, addr);if (vma ==NULL || addr < vma->vm_start || addr + len > vma->vm_end) { -up_read (¤t->mm->mmap_sem); +mmap_read_unlock (current->mm);return -EFAULT ; }
@@ -91,6 +91,6 @@ asmlinkage int sys_cacheflush(unsigned long addr, unsigned long len, int op)if (op &CACHEFLUSH_I )flush_icache_range (addr, addr+len); -up_read (¤t->mm->mmap_sem); +mmap_read_unlock (current->mm);return 0 ; }
arch/sh/kernel/vsyscall/vsyscall.c +2 -2
@@ -61,7 +61,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)unsigned long addr;int ret; -if (down_write_killable (&mm->mmap_sem)) +if (mmap_write_lock_killable (mm))return -EINTR ; addr =get_unmapped_area (NULL ,0 ,PAGE_SIZE ,0 ,0 );
@@ -80,7 +80,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp) current->mm->context.vdso = (void *)addr; up_fail: -up_write (&mm->mmap_sem); +mmap_write_unlock (mm);return ret; }
arch/sh/mm/fault.c +7 -7
@@ -261,7 +261,7 @@ __bad_area(struct pt_regs *regs, unsigned long error_code,* Something tried to access memory that isn't in our memory map.. * Fix it, but check if it's kernel or user first.. */ -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);__bad_area_nosemaphore (regs, error_code, address, si_code); }
@@ -285,7 +285,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address)struct task_struct *tsk = current;struct mm_struct *mm = tsk->mm; -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);/* Kernel mode? Handle exceptions or die: */ if (!user_mode (regs))
@@ -304,7 +304,7 @@ mm_fault_error(struct pt_regs *regs, unsigned long error_code,*/ if (fatal_signal_pending (current)) {if (!(fault &VM_FAULT_RETRY )) -up_read (¤t->mm->mmap_sem); +mmap_read_unlock (current->mm);if (!user_mode (regs))no_context (regs, error_code, address);return 1 ;
@@ -316,11 +316,11 @@ mm_fault_error(struct pt_regs *regs, unsigned long error_code,if (fault &VM_FAULT_OOM ) {/* Kernel mode? Handle exceptions or die: */ if (!user_mode (regs)) { -up_read (¤t->mm->mmap_sem); +mmap_read_unlock (current->mm);no_context (regs, error_code, address);return 1 ; } -up_read (¤t->mm->mmap_sem); +mmap_read_unlock (current->mm);/* * We ran out of memory, call the OOM killer, and return the
@@ -424,7 +424,7 @@ asmlinkage void __kprobes do_page_fault(struct pt_regs *regs, } retry: -down_read (&mm->mmap_sem); +mmap_read_lock (mm); vma =find_vma (mm, address);if (unlikely (!vma)) {
@@ -493,5 +493,5 @@ asmlinkage void __kprobes do_page_fault(struct pt_regs *regs, } } -up_read (&mm->mmap_sem); +mmap_read_unlock (mm); }
arch/sparc/mm/fault_32.c +9 -9
@@ -196,7 +196,7 @@ asmlinkage void do_sparc_fault(struct pt_regs *regs, int text_fault, int write,perf_sw_event (PERF_COUNT_SW_PAGE_FAULTS ,1 , regs, address); retry: -down_read (&mm->mmap_sem); +mmap_read_lock (mm);if (!from_user && address >=PAGE_OFFSET ) goto bad_area;
@@ -273,7 +273,7 @@ asmlinkage void do_sparc_fault(struct pt_regs *regs, int text_fault, int write, } } -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);return ;/*
@@ -281,7 +281,7 @@ asmlinkage void do_sparc_fault(struct pt_regs *regs, int text_fault, int write,* Fix it, but check if it's kernel or user first.. */ bad_area: -up_read (&mm->mmap_sem); +mmap_read_unlock (mm); bad_area_nosemaphore:/* User mode accesses just cause a SIGSEGV */
@@ -330,7 +330,7 @@ asmlinkage void do_sparc_fault(struct pt_regs *regs, int text_fault, int write,* us unable to handle the page fault gracefully. */ out_of_memory: -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);if (from_user) {pagefault_out_of_memory ();return ;
@@ -338,7 +338,7 @@ asmlinkage void do_sparc_fault(struct pt_regs *regs, int text_fault, int write, goto no_context; do_sigbus: -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);do_fault_siginfo (BUS_ADRERR ,SIGBUS , regs, text_fault);if (!from_user) goto no_context;
@@ -392,7 +392,7 @@ static void force_user_fault(unsigned long address, int write) code =SEGV_MAPERR ; -down_read (&mm->mmap_sem); +mmap_read_lock (mm); vma =find_vma (mm, address);if (!vma) goto bad_area;
@@ -417,15 +417,15 @@ static void force_user_fault(unsigned long address, int write)case VM_FAULT_OOM : goto do_sigbus; } -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);return ; bad_area: -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);__do_fault_siginfo (code,SIGSEGV , tsk->thread.kregs, address);return ; do_sigbus: -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);__do_fault_siginfo (BUS_ADRERR ,SIGBUS , tsk->thread.kregs, address); }
arch/sparc/mm/fault_64.c +6 -6
@@ -319,7 +319,7 @@ asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)perf_sw_event (PERF_COUNT_SW_PAGE_FAULTS ,1 , regs, address); -if (!down_read_trylock (&mm->mmap_sem)) { +if (!mmap_read_trylock (mm)) {if ((regs->tstate &TSTATE_PRIV ) && !search_exception_tables (regs->tpc)) { insn =get_fault_insn (regs, insn);
@@ -327,7 +327,7 @@ asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs) } retry: -down_read (&mm->mmap_sem); +mmap_read_lock (mm); }if (fault_code &FAULT_CODE_BAD_RA )
@@ -460,7 +460,7 @@ asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs) goto retry; } } -up_read (&mm->mmap_sem); +mmap_read_unlock (mm); mm_rss =get_mm_rss (mm);#if defined(CONFIG_TRANSPARENT_HUGEPAGE )
@@ -491,7 +491,7 @@ asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)*/ bad_area: insn =get_fault_insn (regs, insn); -up_read (&mm->mmap_sem); +mmap_read_unlock (mm); handle_kernel_fault:do_kernel_fault (regs, si_code, fault_code, insn, address);
@@ -503,7 +503,7 @@ asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)*/ out_of_memory: insn =get_fault_insn (regs, insn); -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);if (!(regs->tstate &TSTATE_PRIV )) {pagefault_out_of_memory (); goto exit_exception;
@@ -516,7 +516,7 @@ asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs) do_sigbus: insn =get_fault_insn (regs, insn); -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);/* * Send a sigbus, regardless of whether we were in kernel
arch/sparc/vdso/vma.c +2 -2
@@ -366,7 +366,7 @@ static int map_vdso(const struct vdso_image *image,unsigned long text_start, addr =0 ;int ret =0 ; -down_write (&mm->mmap_sem); +mmap_write_lock (mm);/* * First, get an unmapped region: then randomize it, and make sure that
@@ -422,7 +422,7 @@ static int map_vdso(const struct vdso_image *image,if (ret) current->mm->context.vdso =NULL ; -up_write (&mm->mmap_sem); +mmap_write_unlock (mm);return ret; }
arch/um/include/asm/mmu_context.h +1 -1
@@ -49,7 +49,7 @@ static inline void activate_mm(struct mm_struct *old, struct mm_struct *new)__switch_mm (&new->context.id);down_write_nested (&new->mmap_sem,1 );uml_setup_stubs (new); -up_write (&new->mmap_sem); +mmap_write_unlock (new); } static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
arch/um/kernel/tlb.c +1 -1
@@ -350,7 +350,7 @@ void fix_range_common(struct mm_struct *mm, unsigned long start_addr,printk (KERN_ERR "fix_range_common: failed, killing current " "process: %d\n" ,task_tgid_vnr (current));/* We are under mmap_sem, release it such that current can terminate */ -up_write (¤t->mm->mmap_sem); +mmap_write_unlock (current->mm);force_sig (SIGKILL );do_signal (¤t->thread.regs); }
arch/um/kernel/trap.c +3 -3
@@ -47,7 +47,7 @@ int handle_page_fault(unsigned long address, unsigned long ip,if (is_user) flags |=FAULT_FLAG_USER ; retry: -down_read (&mm->mmap_sem); +mmap_read_lock (mm); vma =find_vma (mm, address);if (!vma) goto out;
@@ -124,7 +124,7 @@ int handle_page_fault(unsigned long address, unsigned long ip,#endif flush_tlb_page (vma, address); out: -up_read (&mm->mmap_sem); +mmap_read_unlock (mm); out_nosemaphore:return err;
@@ -133,7 +133,7 @@ int handle_page_fault(unsigned long address, unsigned long ip,* We ran out of memory, call the OOM killer, and return the userspace * (which will retry the fault, or kill us if we got oom-killed). */ -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);if (!is_user) goto out_nosemaphore;pagefault_out_of_memory ();
arch/unicore32/mm/fault.c +3 -3
@@ -224,12 +224,12 @@ static int do_pf(unsigned long addr, unsigned int fsr, struct pt_regs *regs)* validly references user space from well defined areas of the code, * we can bug out early if this is from code which shouldn't. */ -if (!down_read_trylock (&mm->mmap_sem)) { +if (!mmap_read_trylock (mm)) {if (!user_mode (regs) && !search_exception_tables (regs->UCreg_pc)) goto no_context; retry: -down_read (&mm->mmap_sem); +mmap_read_lock (mm); }else {/* * The above down_read_trylock() might have succeeded in
@@ -266,7 +266,7 @@ static int do_pf(unsigned long addr, unsigned int fsr, struct pt_regs *regs) } } -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);/* * Handle the "normal" case first - VM_FAULT_MAJOR
arch/x86/entry/vdso/vma.c +7 -7
@@ -142,7 +142,7 @@ int vdso_join_timens(struct task_struct *task, struct time_namespace *ns)struct mm_struct *mm = task->mm;struct vm_area_struct *vma; -if (down_write_killable (&mm->mmap_sem)) +if (mmap_write_lock_killable (mm))return -EINTR ;for (vma = mm->mmap; vma; vma = vma->vm_next) {
@@ -152,7 +152,7 @@ int vdso_join_timens(struct task_struct *task, struct time_namespace *ns) zap_page_range(vma, vma->vm_start, size); } -up_write (&mm->mmap_sem); +mmap_write_unlock (mm);return 0 ; }#else
@@ -266,7 +266,7 @@ static int map_vdso(const struct vdso_image *image, unsigned long addr)unsigned long text_start;int ret =0 ; -if (down_write_killable (&mm->mmap_sem)) +if (mmap_write_lock_killable (mm))return -EINTR ; addr = get_unmapped_area(NULL, addr,
@@ -309,7 +309,7 @@ static int map_vdso(const struct vdso_image *image, unsigned long addr) } up_fail: -up_write (&mm->mmap_sem); +mmap_write_unlock (mm);return ret; }
@@ -371,7 +371,7 @@ int map_vdso_once(const struct vdso_image *image, unsigned long addr)struct mm_struct *mm = current->mm;struct vm_area_struct *vma; -down_write (&mm->mmap_sem); +mmap_write_lock (mm);/* * Check if we have already mapped vdso blob - fail to prevent * abusing from userspace install_speciall_mapping, which may
@@ -382,11 +382,11 @@ int map_vdso_once(const struct vdso_image *image, unsigned long addr)for (vma = mm->mmap; vma; vma = vma->vm_next) {if (vma_is_special_mapping (vma, &vdso_mapping) ||vma_is_special_mapping (vma, &vvar_mapping)) { -up_write (&mm->mmap_sem); +mmap_write_unlock (mm);return -EEXIST ; } } -up_write (&mm->mmap_sem); +mmap_write_unlock (mm);return map_vdso (image, addr); }
arch/x86/kernel/vm86_32.c +2 -2
@@ -172,7 +172,7 @@ static void mark_screen_rdonly(struct mm_struct *mm)pte_t *pte;int i; -down_write (&mm->mmap_sem); +mmap_write_lock (mm); pgd =pgd_offset (mm,0xA0000 );if (pgd_none_or_clear_bad (pgd)) goto out;
@@ -198,7 +198,7 @@ static void mark_screen_rdonly(struct mm_struct *mm) }pte_unmap_unlock (pte, ptl); out: -up_write (&mm->mmap_sem); +mmap_write_unlock (mm);flush_tlb_mm_range (mm,0xA0000 ,0xA0000 +32 *PAGE_SIZE ,PAGE_SHIFT , false); }
arch/x86/mm/fault.c +4 -4
@@ -951,7 +951,7 @@ __bad_area(struct pt_regs *regs, unsigned long error_code,* Something tried to access memory that isn't in our memory map.. * Fix it, but check if it's kernel or user first.. */ -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);__bad_area_nosemaphore (regs, error_code, address, pkey, si_code); }
@@ -1402,7 +1402,7 @@ void do_user_addr_fault(struct pt_regs *regs,* 1. Failed to acquire mmap_sem, and * 2. The access did not originate in userspace. */ -if (unlikely (!down_read_trylock (&mm->mmap_sem))) { +if (unlikely (!mmap_read_trylock (mm))) {if (!user_mode (regs) && !search_exception_tables (regs->ip)) {/* * Fault from code in kernel from
@@ -1412,7 +1412,7 @@ void do_user_addr_fault(struct pt_regs *regs,return ; } retry: -down_read (&mm->mmap_sem); +mmap_read_lock (mm); }else {/* * The above down_read_trylock() might have succeeded in
@@ -1487,7 +1487,7 @@ void do_user_addr_fault(struct pt_regs *regs,return ; } -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);if (unlikely (fault &VM_FAULT_ERROR )) {mm_fault_error (regs, hw_error_code, address, fault);return ;
arch/x86/um/vdso/vma.c +2 -2
@@ -58,7 +58,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)if (!vdso_enabled)return 0 ; -if (down_write_killable (&mm->mmap_sem)) +if (mmap_write_lock_killable (mm))return -EINTR ; err = install_special_mapping(mm, um_vdso_addr, PAGE_SIZE,
@@ -66,7 +66,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)VM_MAYREAD |VM_MAYWRITE |VM_MAYEXEC , vdsop); -up_write (&mm->mmap_sem); +mmap_write_unlock (mm);return err; }
arch/xtensa/mm/fault.c +5 -5
@@ -74,7 +74,7 @@ void do_page_fault(struct pt_regs *regs)if (user_mode (regs)) flags |=FAULT_FLAG_USER ; retry: -down_read (&mm->mmap_sem); +mmap_read_lock (mm); vma =find_vma (mm, address);if (!vma)
@@ -140,7 +140,7 @@ void do_page_fault(struct pt_regs *regs) } } -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);perf_sw_event (PERF_COUNT_SW_PAGE_FAULTS ,1 , regs, address);if (flags &VM_FAULT_MAJOR )perf_sw_event (PERF_COUNT_SW_PAGE_FAULTS_MAJ ,1 , regs, address);
@@ -153,7 +153,7 @@ void do_page_fault(struct pt_regs *regs)* Fix it, but check if it's kernel or user first.. */ bad_area: -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);if (user_mode (regs)) { current->thread.bad_vaddr = address; current->thread.error_code = is_write;
@@ -168,7 +168,7 @@ void do_page_fault(struct pt_regs *regs)* us unable to handle the page fault gracefully. */ out_of_memory: -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);if (!user_mode (regs))bad_page_fault (regs, address,SIGKILL );else
@@ -176,7 +176,7 @@ void do_page_fault(struct pt_regs *regs)return ; do_sigbus: -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);/* Send a sigbus, regardless of whether we were in kernel * or user mode.
drivers/android/binder_alloc.c +3 -3
@@ -212,7 +212,7 @@ static int binder_update_page_range(struct binder_alloc *alloc, int allocate, mm = alloc->vma_vm_mm;if (mm) { -down_read (&mm->mmap_sem); +mmap_read_lock (mm); vma = alloc->vma; }
@@ -270,7 +270,7 @@ static int binder_update_page_range(struct binder_alloc *alloc, int allocate,trace_binder_alloc_page_end (alloc, index); }if (mm) { -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);mmput (mm); }return 0 ;
@@ -303,7 +303,7 @@ static int binder_update_page_range(struct binder_alloc *alloc, int allocate, } err_no_vma:if (mm) { -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);mmput (mm); }return vma ? -ENOMEM : -ESRCH ;
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +2 -2
@@ -1343,9 +1343,9 @@ int amdgpu_amdkfd_gpuvm_map_memory_to_gpu(* concurrently and the queues are actually stopped */ if (amdgpu_ttm_tt_get_usermm (bo->tbo.ttm)) { -down_write (¤t->mm->mmap_sem); +mmap_write_lock (current->mm); is_invalid_userptr =atomic_read (&mem->invalid); -up_write (¤t->mm->mmap_sem); +mmap_write_unlock (current->mm); }mutex_lock (&mem->lock);
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +5 -5
@@ -839,7 +839,7 @@ int amdgpu_ttm_tt_get_user_pages(struct amdgpu_bo *bo, struct page **pages) goto out_free_ranges; } -down_read (&mm->mmap_sem); +mmap_read_lock (mm); vma =find_vma (mm, start);if (unlikely (!vma || start < vma->vm_start)) { r = -EFAULT ;
@@ -850,15 +850,15 @@ int amdgpu_ttm_tt_get_user_pages(struct amdgpu_bo *bo, struct page **pages) r = -EPERM ; goto out_unlock; } -up_read (&mm->mmap_sem); +mmap_read_unlock (mm); timeout = jiffies +msecs_to_jiffies (HMM_RANGE_DEFAULT_TIMEOUT ); retry: range->notifier_seq =mmu_interval_read_begin (&bo->notifier); -down_read (&mm->mmap_sem); +mmap_read_lock (mm); r =hmm_range_fault (range,0 ); -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);if (unlikely (r <=0 )) {/* * FIXME: This timeout should encompass the retry from
@@ -887,7 +887,7 @@ int amdgpu_ttm_tt_get_user_pages(struct amdgpu_bo *bo, struct page **pages)return 0 ; out_unlock: -up_read (&mm->mmap_sem); +mmap_read_unlock (mm); out_free_pfns:kvfree (range->pfns); out_free_ranges:
drivers/gpu/drm/amd/amdkfd/kfd_events.c +2 -2
@@ -901,7 +901,7 @@ void kfd_signal_iommu_event(struct kfd_dev *dev, unsigned int pasid,memset (&memory_exception_data,0 ,sizeof (memory_exception_data)); -down_read (&mm->mmap_sem); +mmap_read_lock (mm); vma =find_vma (mm, address); memory_exception_data.gpu_id = dev->id;
@@ -924,7 +924,7 @@ void kfd_signal_iommu_event(struct kfd_dev *dev, unsigned int pasid, memory_exception_data.failure.NoExecute =0 ; } -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);mmput (mm); pr_debug("notpresent %d, noexecute %d, readonly %d\n",
drivers/gpu/drm/i915/gem/i915_gem_mman.c +2 -2
@@ -93,7 +93,7 @@ i915_gem_mmap_ioctl(struct drm_device *dev, void *data,struct mm_struct *mm = current->mm;struct vm_area_struct *vma; -if (down_write_killable (&mm->mmap_sem)) { +if (mmap_write_lock_killable (mm)) { addr = -EINTR ; goto err; }
@@ -103,7 +103,7 @@ i915_gem_mmap_ioctl(struct drm_device *dev, void *data,pgprot_writecombine (vm_get_page_prot (vma->vm_flags)); else addr = -ENOMEM ; -up_write (&mm->mmap_sem); +mmap_write_unlock (mm);if (IS_ERR_VALUE (addr)) goto err; }
drivers/gpu/drm/i915/gem/i915_gem_userptr.c +4 -4
@@ -202,7 +202,7 @@ i915_mmu_notifier_find(struct i915_mm_struct *mm)if (IS_ERR (mn)) err =PTR_ERR (mn); -down_write (&mm->mm->mmap_sem); +mmap_write_lock (mm->mm);mutex_lock (&mm->i915->mm_lock);if (mm->mn ==NULL && !err) {/* Protected by mmap_sem (write-lock) */
@@ -219,7 +219,7 @@ i915_mmu_notifier_find(struct i915_mm_struct *mm) err =0 ; }mutex_unlock (&mm->i915->mm_lock); -up_write (&mm->mm->mmap_sem); +mmap_write_unlock (mm->mm);if (mn && !IS_ERR (mn))kfree (mn);
@@ -470,7 +470,7 @@ __i915_gem_userptr_get_pages_worker(struct work_struct *_work)if (mmget_not_zero (mm)) {while (pinned < npages) {if (!locked) { -down_read (&mm->mmap_sem); +mmap_read_lock (mm); locked =1 ; } ret = get_user_pages_remote
@@ -485,7 +485,7 @@ __i915_gem_userptr_get_pages_worker(struct work_struct *_work) pinned += ret; }if (locked) -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);mmput (mm); } }
drivers/gpu/drm/nouveau/nouveau_svm.c +10 -10
@@ -169,7 +169,7 @@ nouveau_svmm_bind(struct drm_device *dev, void *data,*/ mm =get_task_mm (current); -down_read (&mm->mmap_sem); +mmap_read_lock (mm);for (addr = args->va_start, end = args->va_start + size; addr < end;) {struct vm_area_struct *vma;
@@ -192,7 +192,7 @@ nouveau_svmm_bind(struct drm_device *dev, void *data,*/ args->result =0 ; -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);mmput (mm);return 0 ;
@@ -342,7 +342,7 @@ nouveau_svmm_init(struct drm_device *dev, void *data,if (ret) goto out_free; -down_write (¤t->mm->mmap_sem); +mmap_write_lock (current->mm); svmm->notifier.ops = &nouveau_mn_ops; ret =__mmu_notifier_register (&svmm->notifier, current->mm);if (ret)
@@ -351,12 +351,12 @@ nouveau_svmm_init(struct drm_device *dev, void *data, cli->svm.svmm = svmm; cli->svm.cli = cli; -up_write (¤t->mm->mmap_sem); +mmap_write_unlock (current->mm);mutex_unlock (&cli->mutex);return 0 ; out_mm_unlock: -up_write (¤t->mm->mmap_sem); +mmap_write_unlock (current->mm); out_free:mutex_unlock (&cli->mutex);kfree (svmm);
@@ -540,9 +540,9 @@ static int nouveau_range_fault(struct nouveau_svmm *svmm, range.notifier_seq =mmu_interval_read_begin (range.notifier); range.default_flags =0 ; range.pfn_flags_mask =-1UL ; -down_read (&mm->mmap_sem); +mmap_read_lock (mm); ret =hmm_range_fault (&range,0 ); -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);if (ret <=0 ) {if (ret ==0 || ret == -EBUSY )continue ;
@@ -671,18 +671,18 @@ nouveau_svm_fault(struct nvif_notify *notify)/* Intersect fault window with the CPU VMA, cancelling * the fault if the address is invalid. */ -down_read (&mm->mmap_sem); +mmap_read_lock (mm); vma =find_vma_intersection (mm, start, limit);if (!vma) {SVMM_ERR (svmm,"wndw %016llx-%016llx" , start, limit); -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);mmput (mm);nouveau_svm_fault_cancel_fault (svm, buffer->fault[fi]);continue ; } start =max_t (u64, start, vma->vm_start); limit =min_t (u64, limit, vma->vm_end); -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);SVMM_DBG (svmm,"wndw %016llx-%016llx" , start, limit);if (buffer->fault[fi]->addr != start) {
drivers/gpu/drm/radeon/radeon_cs.c +2 -2
@@ -196,12 +196,12 @@ static int radeon_cs_parser_relocs(struct radeon_cs_parser *p) p->vm_bos =radeon_vm_get_bos (p->rdev, p->ib.vm, &p->validated);if (need_mmap_lock) -down_read (¤t->mm->mmap_sem); +mmap_read_lock (current->mm); r =radeon_bo_list_validate (p->rdev, &p->ticket, &p->validated, p->ring);if (need_mmap_lock) -up_read (¤t->mm->mmap_sem); +mmap_read_unlock (current->mm);return r; }
drivers/gpu/drm/radeon/radeon_gem.c +3 -3
@@ -342,17 +342,17 @@ int radeon_gem_userptr_ioctl(struct drm_device *dev, void *data, }if (args->flags &RADEON_GEM_USERPTR_VALIDATE ) { -down_read (¤t->mm->mmap_sem); +mmap_read_lock (current->mm); r =radeon_bo_reserve (bo, true);if (r) { -up_read (¤t->mm->mmap_sem); +mmap_read_unlock (current->mm); goto release_object; }radeon_ttm_placement_from_domain (bo,RADEON_GEM_DOMAIN_GTT ); r =ttm_bo_validate (&bo->tbo, &bo->placement, &ctx);radeon_bo_unreserve (bo); -up_read (¤t->mm->mmap_sem); +mmap_read_unlock (current->mm);if (r) goto release_object; }
drivers/gpu/drm/ttm/ttm_bo_vm.c +2 -2
@@ -67,7 +67,7 @@ static vm_fault_t ttm_bo_vm_fault_idle(struct ttm_buffer_object *bo, goto out_unlock;ttm_bo_get (bo); -up_read (&vmf->vma->vm_mm->mmap_sem); +mmap_read_unlock (vmf->vma->vm_mm); (void )dma_fence_wait (bo->moving, true);dma_resv_unlock (bo->base.resv);ttm_bo_put (bo);
@@ -138,7 +138,7 @@ vm_fault_t ttm_bo_vm_reserve(struct ttm_buffer_object *bo,if (vmf->flags &FAULT_FLAG_ALLOW_RETRY ) {if (!(vmf->flags &FAULT_FLAG_RETRY_NOWAIT )) {ttm_bo_get (bo); -up_read (&vmf->vma->vm_mm->mmap_sem); +mmap_read_unlock (vmf->vma->vm_mm);if (!dma_resv_lock_interruptible (bo->base.resv,NULL ))dma_resv_unlock (bo->base.resv);
drivers/infiniband/core/umem_odp.c +2 -2
@@ -429,7 +429,7 @@ int ib_umem_odp_map_dma_pages(struct ib_umem_odp *umem_odp, u64 user_virt,ALIGN (bcnt,PAGE_SIZE ) /PAGE_SIZE , PAGE_SIZE / sizeof(struct page *)); -down_read (&owning_mm->mmap_sem); +mmap_read_lock (owning_mm);/* * Note: this might result in redundent page getting. We can * avoid this by checking dma_list to be 0 before calling
@@ -440,7 +440,7 @@ int ib_umem_odp_map_dma_pages(struct ib_umem_odp *umem_odp, u64 user_virt, npages =get_user_pages_remote (owning_process, owning_mm, user_virt, gup_num_pages, flags, local_page_list,NULL ,NULL ); -up_read (&owning_mm->mmap_sem); +mmap_read_unlock (owning_mm);if (npages <0 ) {if (npages != -EAGAIN )
drivers/infiniband/core/uverbs_main.c +2 -2
@@ -835,7 +835,7 @@ void uverbs_user_mmap_disassociate(struct ib_uverbs_file *ufile)* at a time to get the lock ordering right. Typically there * will only be one mm, so no big deal. */ -down_read (&mm->mmap_sem); +mmap_read_lock (mm);if (!mmget_still_valid (mm)) goto skip_mm;mutex_lock (&ufile->umap_lock);
@@ -857,7 +857,7 @@ void uverbs_user_mmap_disassociate(struct ib_uverbs_file *ufile) }mutex_unlock (&ufile->umap_lock); skip_mm: -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);mmput (mm); } }
drivers/infiniband/hw/mlx4/mr.c +2 -2
@@ -380,7 +380,7 @@ static struct ib_umem *mlx4_get_umem_mr(struct ib_device *device, u64 start,unsigned long untagged_start =untagged_addr (start);struct vm_area_struct *vma; -down_read (¤t->mm->mmap_sem); +mmap_read_lock (current->mm);/* * FIXME: Ideally this would iterate over all the vmas that * cover the memory, but for now it requires a single vma to
@@ -395,7 +395,7 @@ static struct ib_umem *mlx4_get_umem_mr(struct ib_device *device, u64 start, access_flags |=IB_ACCESS_LOCAL_WRITE ; } -up_read (¤t->mm->mmap_sem); +mmap_read_unlock (current->mm); }return ib_umem_get (device, start, length, access_flags);
drivers/infiniband/hw/qib/qib_user_pages.c +3 -3
@@ -106,18 +106,18 @@ int qib_get_user_pages(unsigned long start_page, size_t num_pages, goto bail; } -down_read (¤t->mm->mmap_sem); +mmap_read_lock (current->mm);for (got =0 ; got < num_pages; got += ret) { ret =pin_user_pages (start_page + got *PAGE_SIZE , num_pages - got,FOLL_LONGTERM |FOLL_WRITE |FOLL_FORCE , p + got,NULL );if (ret <0 ) { -up_read (¤t->mm->mmap_sem); +mmap_read_unlock (current->mm); goto bail_release; } } -up_read (¤t->mm->mmap_sem); +mmap_read_unlock (current->mm);return 0 ; bail_release:
drivers/infiniband/hw/usnic/usnic_uiom.c +2 -2
@@ -123,7 +123,7 @@ static int usnic_uiom_get_pages(unsigned long addr, size_t size, int writable, npages =PAGE_ALIGN (size + (addr & ~PAGE_MASK )) >>PAGE_SHIFT ; uiomr->owning_mm = mm = current->mm; -down_read (&mm->mmap_sem); +mmap_read_lock (mm); locked =atomic64_add_return (npages, ¤t->mm->pinned_vm); lock_limit =rlimit (RLIMIT_MEMLOCK ) >>PAGE_SHIFT ;
@@ -187,7 +187,7 @@ static int usnic_uiom_get_pages(unsigned long addr, size_t size, int writable, }else mmgrab (uiomr->owning_mm); -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);free_page ((unsigned long ) page_list);return ret; }
drivers/infiniband/sw/siw/siw_mem.c +2 -2
@@ -397,7 +397,7 @@ struct siw_umem *siw_umem_get(u64 start, u64 len, bool writable)if (!writable) foll_flags |=FOLL_FORCE ; -down_read (&mm_s->mmap_sem); +mmap_read_lock (mm_s); mlock_limit =rlimit (RLIMIT_MEMLOCK ) >>PAGE_SHIFT ;
@@ -441,7 +441,7 @@ struct siw_umem *siw_umem_get(u64 start, u64 len, bool writable) num_pages -= got; } out_sem_up: -up_read (&mm_s->mmap_sem); +mmap_read_unlock (mm_s);if (rv >0 )return umem;
drivers/iommu/amd_iommu_v2.c +2 -2
@@ -487,7 +487,7 @@ static void do_fault(struct work_struct *work) flags |=FAULT_FLAG_WRITE ; flags |=FAULT_FLAG_REMOTE ; -down_read (&mm->mmap_sem); +mmap_read_lock (mm); vma =find_extend_vma (mm, address);if (!vma || address < vma->vm_start)/* failed to get a vma in the right range */
@@ -499,7 +499,7 @@ static void do_fault(struct work_struct *work) ret =handle_mm_fault (vma, address, flags); out: -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);if (ret &VM_FAULT_ERROR )/* failed to service fault */
drivers/iommu/intel-svm.c +2 -2
@@ -619,7 +619,7 @@ static irqreturn_t prq_event_thread(int irq, void *d)if (!is_canonical_address (address)) goto bad_req; -down_read (&svm->mm->mmap_sem); +mmap_read_lock (svm->mm); vma =find_extend_vma (svm->mm, address);if (!vma || address < vma->vm_start) goto invalid;
@@ -634,7 +634,7 @@ static irqreturn_t prq_event_thread(int irq, void *d) result =QI_RESP_SUCCESS ; invalid: -up_read (&svm->mm->mmap_sem); +mmap_read_unlock (svm->mm);mmput (svm->mm); bad_req:/* Accounting for major/minor faults? */
drivers/media/v4l2-core/videobuf-core.c +2 -2
@@ -535,7 +535,7 @@ int videobuf_qbuf(struct videobuf_queue *q, struct v4l2_buffer *b)MAGIC_CHECK (q->int_ops->magic,MAGIC_QTYPE_OPS );if (b->memory ==V4L2_MEMORY_MMAP ) -down_read (¤t->mm->mmap_sem); +mmap_read_lock (current->mm);videobuf_queue_lock (q); retval = -EBUSY ;
@@ -622,7 +622,7 @@ int videobuf_qbuf(struct videobuf_queue *q, struct v4l2_buffer *b)videobuf_queue_unlock (q);if (b->memory ==V4L2_MEMORY_MMAP ) -up_read (¤t->mm->mmap_sem); +mmap_read_unlock (current->mm);return retval; }
drivers/media/v4l2-core/videobuf-dma-contig.c +2 -2
@@ -169,7 +169,7 @@ static int videobuf_dma_contig_user_get(struct videobuf_dma_contig_memory *mem, mem->size =PAGE_ALIGN (vb->size + offset); ret = -EINVAL ; -down_read (&mm->mmap_sem); +mmap_read_lock (mm); vma =find_vma (mm, untagged_baddr);if (!vma)
@@ -201,7 +201,7 @@ static int videobuf_dma_contig_user_get(struct videobuf_dma_contig_memory *mem, } out_up: -up_read (¤t->mm->mmap_sem); +mmap_read_unlock (current->mm);return ret; }
drivers/media/v4l2-core/videobuf-dma-sg.c +2 -2
@@ -200,9 +200,9 @@ static int videobuf_dma_init_user(struct videobuf_dmabuf *dma, int direction, {int ret; -down_read (¤t->mm->mmap_sem); +mmap_read_lock (current->mm); ret =videobuf_dma_init_user_locked (dma, direction, data, size); -up_read (¤t->mm->mmap_sem); +mmap_read_unlock (current->mm);return ret; }
drivers/misc/cxl/cxllib.c +2 -2
@@ -207,7 +207,7 @@ static int get_vma_info(struct mm_struct *mm, u64 addr,struct vm_area_struct *vma =NULL ;int rc =0 ; -down_read (&mm->mmap_sem); +mmap_read_lock (mm); vma =find_vma (mm, addr);if (!vma) {
@@ -218,7 +218,7 @@ static int get_vma_info(struct mm_struct *mm, u64 addr, *vma_start = vma->vm_start; *vma_end = vma->vm_end; out: -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);return rc; }
drivers/misc/cxl/fault.c +2 -2
@@ -321,7 +321,7 @@ static void cxl_prefault_vma(struct cxl_context *ctx)return ; } -down_read (&mm->mmap_sem); +mmap_read_lock (mm);for (vma = mm->mmap; vma; vma = vma->vm_next) {for (ea = vma->vm_start; ea < vma->vm_end; ea =next_segment (ea, slb.vsid)) {
@@ -336,7 +336,7 @@ static void cxl_prefault_vma(struct cxl_context *ctx) last_esid = slb.esid; } } -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);mmput (mm); }
drivers/misc/sgi-gru/grufault.c +8 -8
@@ -69,14 +69,14 @@ static struct gru_thread_state *gru_find_lock_gts(unsigned long vaddr)struct vm_area_struct *vma;struct gru_thread_state *gts =NULL ; -down_read (&mm->mmap_sem); +mmap_read_lock (mm); vma =gru_find_vma (vaddr);if (vma) gts =gru_find_thread_state (vma,TSID (vaddr, vma));if (gts)mutex_lock (>s->ts_ctxlock);else -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);return gts; }
@@ -86,7 +86,7 @@ static struct gru_thread_state *gru_alloc_locked_gts(unsigned long vaddr)struct vm_area_struct *vma;struct gru_thread_state *gts =ERR_PTR (-EINVAL ); -down_write (&mm->mmap_sem); +mmap_write_lock (mm); vma =gru_find_vma (vaddr);if (!vma) goto err;
@@ -95,11 +95,11 @@ static struct gru_thread_state *gru_alloc_locked_gts(unsigned long vaddr)if (IS_ERR (gts)) goto err;mutex_lock (>s->ts_ctxlock); -downgrade_write (&mm->mmap_sem); +mmap_downgrade_write_lock (mm);return gts; err: -up_write (&mm->mmap_sem); +mmap_write_unlock (mm);return gts; }
@@ -109,7 +109,7 @@ static struct gru_thread_state *gru_alloc_locked_gts(unsigned long vaddr)static void gru_unlock_gts (struct gru_thread_state *gts) {mutex_unlock (>s->ts_ctxlock); -up_read (¤t->mm->mmap_sem); +mmap_read_unlock (current->mm); }/*
@@ -575,9 +575,9 @@ static irqreturn_t gru_intr(int chiplet, int blade)*/ gts->ustats.fmm_tlbmiss++;if (!gts->ts_force_cch_reload && -down_read_trylock (>s->ts_mm->mmap_sem)) { +mmap_read_trylock (gts->ts_mm)) {gru_try_dropin (gru, gts, tfh,NULL ); -up_read (>s->ts_mm->mmap_sem); +mmap_read_unlock (gts->ts_mm); }else {tfh_user_polling_mode (tfh);STAT (intr_mm_lock_failed);
drivers/misc/sgi-gru/grufile.c +2 -2
@@ -135,7 +135,7 @@ static int gru_create_new_context(unsigned long arg)if (!(req.options &GRU_OPT_MISS_MASK )) req.options |=GRU_OPT_MISS_FMM_INTR ; -down_write (¤t->mm->mmap_sem); +mmap_write_lock (current->mm); vma =gru_find_vma (req.gseg);if (vma) { vdata = vma->vm_private_data;
@@ -146,7 +146,7 @@ static int gru_create_new_context(unsigned long arg) vdata->vd_tlb_preload_count = req.tlb_preload_count; ret =0 ; } -up_write (¤t->mm->mmap_sem); +mmap_write_unlock (current->mm);return ret; }
drivers/oprofile/buffer_sync.c +5 -5
@@ -91,11 +91,11 @@ munmap_notify(struct notifier_block *self, unsigned long val, void *data)struct mm_struct *mm = current->mm;struct vm_area_struct *mpnt; -down_read (&mm->mmap_sem); +mmap_read_lock (mm); mpnt =find_vma (mm, addr);if (mpnt && mpnt->vm_file && (mpnt->vm_flags &VM_EXEC )) { -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);/* To avoid latency problems, we only process the current CPU, * hoping that most samples for the task are on this CPU */
@@ -103,7 +103,7 @@ munmap_notify(struct notifier_block *self, unsigned long val, void *data)return 0 ; } -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);return 0 ; }
@@ -256,7 +256,7 @@ lookup_dcookie(struct mm_struct *mm, unsigned long addr, off_t *offset)unsigned long cookie =NO_COOKIE ;struct vm_area_struct *vma; -down_read (&mm->mmap_sem); +mmap_read_lock (mm);for (vma =find_vma (mm, addr); vma; vma = vma->vm_next) {if (addr < vma->vm_start || addr >= vma->vm_end)
@@ -276,7 +276,7 @@ lookup_dcookie(struct mm_struct *mm, unsigned long addr, off_t *offset)if (!vma) cookie =INVALID_COOKIE ; -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);return cookie; }
drivers/staging/kpc2000/kpc_dma/fileops.c +2 -2
@@ -74,9 +74,9 @@ static int kpc_dma_transfer(struct dev_private_data *priv, }// Lock the user buffer pages in memory, and hold on to the page pointers (for the sglist) -down_read (¤t->mm->mmap_sem);/* get memory map semaphore */ +mmap_read_lock (current->mm);/* get memory map semaphore */ rv =get_user_pages (iov_base, acd->page_count,FOLL_TOUCH |FOLL_WRITE |FOLL_GET , acd->user_pages,NULL ); -up_read (¤t->mm->mmap_sem);/* release the semaphore */ +mmap_read_unlock (current->mm);/* release the semaphore */ if (rv != acd->page_count) {dev_err (&priv->ldev->pldev->dev,"Couldn't get_user_pages (%ld)\n" , rv); goto err_get_user_pages;
drivers/tee/optee/call.c +2 -2
@@ -561,10 +561,10 @@ static int check_mem_type(unsigned long start, size_t num_pages)if (virt_addr_valid (start))return 0 ; -down_read (&mm->mmap_sem); +mmap_read_lock (mm); rc =__check_mem_type (find_vma (mm, start), start + num_pages *PAGE_SIZE ); -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);return rc; }
drivers/vfio/vfio_iommu_type1.c +4 -4
@@ -277,11 +277,11 @@ static int vfio_lock_acct(struct vfio_dma *dma, long npage, bool async)if (!mm)return -ESRCH ;/* process exited */ - ret =down_write_killable (&mm->mmap_sem); + ret =mmap_write_lock_killable (mm);if (!ret) { ret =__account_locked_vm (mm,abs (npage), npage >0 , dma->task, dma->lock_cap); -up_write (&mm->mmap_sem); +mmap_write_unlock (mm); }if (async)
@@ -327,7 +327,7 @@ static int vaddr_get_pfn(struct mm_struct *mm, unsigned long vaddr,if (prot &IOMMU_WRITE ) flags |=FOLL_WRITE ; -down_read (&mm->mmap_sem); +mmap_read_lock (mm); ret =pin_user_pages_remote (NULL , mm, vaddr,1 , flags |FOLL_LONGTERM , page,NULL ,NULL );if (ret ==1 ) {
@@ -346,7 +346,7 @@ static int vaddr_get_pfn(struct mm_struct *mm, unsigned long vaddr, ret =0 ; } done: -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);return ret; }
drivers/xen/gntdev.c +2 -2
@@ -625,7 +625,7 @@ static long gntdev_ioctl_get_offset_for_vaddr(struct gntdev_priv *priv,return -EFAULT ;pr_debug ("priv %p, offset for vaddr %lx\n" , priv, (unsigned long )op.vaddr); -down_read (¤t->mm->mmap_sem); +mmap_read_lock (current->mm); vma =find_vma (current->mm, op.vaddr);if (!vma || vma->vm_ops != &gntdev_vmops) goto out_unlock;
@@ -639,7 +639,7 @@ static long gntdev_ioctl_get_offset_for_vaddr(struct gntdev_priv *priv, rv =0 ; out_unlock: -up_read (¤t->mm->mmap_sem); +mmap_read_unlock (current->mm);if (rv ==0 &©_to_user (u, &op,sizeof (op)) !=0 )return -EFAULT ;
drivers/xen/privcmd.c +7 -7
@@ -278,7 +278,7 @@ static long privcmd_ioctl_mmap(struct file *file, void __user *udata)if (rc ||list_empty (&pagelist)) goto out; -down_write (&mm->mmap_sem); +mmap_write_lock (mm); { struct page *page = list_first_entry(&pagelist,
@@ -303,7 +303,7 @@ static long privcmd_ioctl_mmap(struct file *file, void __user *udata) out_up: -up_write (&mm->mmap_sem); +mmap_write_unlock (mm); out:free_page_list (&pagelist);
@@ -499,7 +499,7 @@ static long privcmd_ioctl_mmap_batch( } } -down_write (&mm->mmap_sem); +mmap_write_lock (mm); vma =find_vma (mm, m.addr); if (!vma ||
@@ -555,7 +555,7 @@ static long privcmd_ioctl_mmap_batch(BUG_ON (traverse_pages_block (m.num,sizeof (xen_pfn_t), &pagelist, mmap_batch_fn, &state)); -up_write (&mm->mmap_sem); +mmap_write_unlock (mm);if (state.global_error) {/* Write back errors in second pass. */
@@ -576,7 +576,7 @@ static long privcmd_ioctl_mmap_batch(return ret; out_unlock: -up_write (&mm->mmap_sem); +mmap_write_unlock (mm); goto out; }
@@ -741,7 +741,7 @@ static long privcmd_ioctl_mmap_resource(struct file *file, void __user *udata)if (data->domid !=DOMID_INVALID && data->domid != kdata.dom)return -EPERM ; -down_write (&mm->mmap_sem); +mmap_write_lock (mm); vma =find_vma (mm, kdata.addr);if (!vma || vma->vm_ops != &privcmd_vm_ops) {
@@ -820,7 +820,7 @@ static long privcmd_ioctl_mmap_resource(struct file *file, void __user *udata) } out: -up_write (&mm->mmap_sem); +mmap_write_unlock (mm);kfree (pfns);return rc;
fs/aio.c +2 -2
@@ -519,7 +519,7 @@ static int aio_setup_ring(struct kioctx *ctx, unsigned int nr_events) ctx->mmap_size = nr_pages *PAGE_SIZE ;pr_debug ("attempting mmap of %lu bytes\n" , ctx->mmap_size); -if (down_write_killable (&mm->mmap_sem)) { +if (mmap_write_lock_killable (mm)) { ctx->mmap_size =0 ;aio_free_ring (ctx);return -EINTR ;
@@ -528,7 +528,7 @@ static int aio_setup_ring(struct kioctx *ctx, unsigned int nr_events) ctx->mmap_base =do_mmap_pgoff (ctx->aio_ring_file,0 , ctx->mmap_size,PROT_READ |PROT_WRITE ,MAP_SHARED ,0 , &unused,NULL ); -up_write (&mm->mmap_sem); +mmap_write_unlock (mm);if (IS_ERR ((void *)ctx->mmap_base)) { ctx->mmap_size =0 ;aio_free_ring (ctx);
fs/coredump.c +2 -2
@@ -443,12 +443,12 @@ static int coredump_wait(int exit_code, struct core_state *core_state) core_state->dumper.task = tsk; core_state->dumper.next =NULL ; -if (down_write_killable (&mm->mmap_sem)) +if (mmap_write_lock_killable (mm))return -EINTR ;if (!mm->core_state) core_waiters =zap_threads (tsk, mm, core_state, exit_code); -up_write (&mm->mmap_sem); +mmap_write_unlock (mm);if (core_waiters >0 ) {struct core_thread *ptr;
fs/exec.c +8 -8
@@ -250,7 +250,7 @@ static int __bprm_mm_init(struct linux_binprm *bprm)return -ENOMEM ;vma_set_anonymous (vma); -if (down_write_killable (&mm->mmap_sem)) { +if (mmap_write_lock_killable (mm)) { err = -EINTR ; goto err_free; }
@@ -272,11 +272,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm) goto err; mm->stack_vm = mm->total_vm =1 ; -up_write (&mm->mmap_sem); +mmap_write_unlock (mm); bprm->p = vma->vm_end -sizeof (void *);return 0 ; err: -up_write (&mm->mmap_sem); +mmap_write_unlock (mm); err_free: bprm->vma =NULL ;vm_area_free (vma);
@@ -737,7 +737,7 @@ int setup_arg_pages(struct linux_binprm *bprm, bprm->loader -= stack_shift; bprm->exec -= stack_shift; -if (down_write_killable (&mm->mmap_sem)) +if (mmap_write_lock_killable (mm))return -EINTR ; vm_flags =VM_STACK_FLAGS ;
@@ -799,7 +799,7 @@ int setup_arg_pages(struct linux_binprm *bprm, ret = -EFAULT ; out_unlock: -up_write (&mm->mmap_sem); +mmap_write_unlock (mm);return ret; }EXPORT_SYMBOL (setup_arg_pages);
@@ -1028,9 +1028,9 @@ static int exec_mmap(struct mm_struct *mm)* through with the exec. We must hold mmap_sem around * checking core_state and changing tsk->mm. */ -down_read (&old_mm->mmap_sem); +mmap_read_lock (old_mm);if (unlikely (old_mm->core_state)) { -up_read (&old_mm->mmap_sem); +mmap_read_unlock (old_mm);return -EINTR ; } }
@@ -1044,7 +1044,7 @@ static int exec_mmap(struct mm_struct *mm)vmacache_flush (tsk);task_unlock (tsk);if (old_mm) { -up_read (&old_mm->mmap_sem); +mmap_read_unlock (old_mm);BUG_ON (active_mm != old_mm);setmax_mm_hiwater_rss (&tsk->signal->maxrss, old_mm);mm_update_next_owner (old_mm);
fs/io_uring.c +2 -2
@@ -6266,7 +6266,7 @@ static int io_sqe_buffer_register(struct io_ring_ctx *ctx, void __user *arg, } ret =0 ; -down_read (¤t->mm->mmap_sem); +mmap_read_lock (current->mm); pret =pin_user_pages (ubuf, nr_pages,FOLL_WRITE |FOLL_LONGTERM , pages, vmas);
@@ -6284,7 +6284,7 @@ static int io_sqe_buffer_register(struct io_ring_ctx *ctx, void __user *arg, }else { ret = pret <0 ? pret : -EFAULT ; } -up_read (¤t->mm->mmap_sem); +mmap_read_unlock (current->mm);if (ret) {/* * if we did partial map, or found file backed vmas,
fs/proc/base.c +6 -6
@@ -2070,11 +2070,11 @@ static int map_files_d_revalidate(struct dentry *dentry, unsigned int flags) goto out;if (!dname_to_vma_addr (dentry, &vm_start, &vm_end)) { - status =down_read_killable (&mm->mmap_sem); + status =mmap_read_lock_killable (mm);if (!status) { exact_vma_exists = !!find_exact_vma (mm, vm_start, vm_end); -up_read (&mm->mmap_sem); +mmap_read_unlock (mm); } }
@@ -2121,7 +2121,7 @@ static int map_files_get_link(struct dentry *dentry, struct path *path)if (rc) goto out_mmput; - rc =down_read_killable (&mm->mmap_sem); + rc =mmap_read_lock_killable (mm);if (rc) goto out_mmput;
@@ -2132,7 +2132,7 @@ static int map_files_get_link(struct dentry *dentry, struct path *path)path_get (path); rc =0 ; } -up_read (&mm->mmap_sem); +mmap_read_unlock (mm); out_mmput:mmput (mm);
@@ -2222,7 +2222,7 @@ static struct dentry *proc_map_files_lookup(struct inode *dir, goto out_put_task; result =ERR_PTR (-EINTR ); -if (down_read_killable (&mm->mmap_sem)) +if (mmap_read_lock_killable (mm)) goto out_put_mm; result =ERR_PTR (-ENOENT );
@@ -2235,7 +2235,7 @@ static struct dentry *proc_map_files_lookup(struct inode *dir, (void *)(unsigned long)vma->vm_file->f_mode); out_no_vma: -up_read (&mm->mmap_sem); +mmap_read_unlock (mm); out_put_mm:mmput (mm); out_put_task:
fs/proc/task_mmu.c +14 -14
@@ -128,7 +128,7 @@ static void vma_stop(struct proc_maps_private *priv)struct mm_struct *mm = priv->mm;release_task_mempolicy (priv); -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);mmput (mm); }
@@ -166,7 +166,7 @@ static void *m_start(struct seq_file *m, loff_t *ppos)if (!mm || !mmget_not_zero (mm))return NULL ; -if (down_read_killable (&mm->mmap_sem)) { +if (mmap_read_lock_killable (mm)) {mmput (mm);return ERR_PTR (-EINTR ); }
@@ -873,7 +873,7 @@ static int show_smaps_rollup(struct seq_file *m, void *v)memset (&mss,0 ,sizeof (mss)); - ret =down_read_killable (&mm->mmap_sem); + ret =mmap_read_lock_killable (mm);if (ret) goto out_put_mm;
@@ -892,7 +892,7 @@ static int show_smaps_rollup(struct seq_file *m, void *v)__show_smap (m, &mss, true);release_task_mempolicy (priv); -up_read (&mm->mmap_sem); +mmap_read_unlock (mm); out_put_mm:mmput (mm);
@@ -1166,7 +1166,7 @@ static ssize_t clear_refs_write(struct file *file, const char __user *buf, };if (type ==CLEAR_REFS_MM_HIWATER_RSS ) { -if (down_write_killable (&mm->mmap_sem)) { +if (mmap_write_lock_killable (mm)) { count = -EINTR ; goto out_mm; }
@@ -1176,11 +1176,11 @@ static ssize_t clear_refs_write(struct file *file, const char __user *buf,* resident set size to this mm's current rss value. */ reset_mm_hiwater_rss (mm); -up_write (&mm->mmap_sem); +mmap_write_unlock (mm); goto out_mm; } -if (down_read_killable (&mm->mmap_sem)) { +if (mmap_read_lock_killable (mm)) { count = -EINTR ; goto out_mm; }
@@ -1189,8 +1189,8 @@ static ssize_t clear_refs_write(struct file *file, const char __user *buf,for (vma = mm->mmap; vma; vma = vma->vm_next) {if (!(vma->vm_flags &VM_SOFTDIRTY ))continue ; -up_read (&mm->mmap_sem); -if (down_write_killable (&mm->mmap_sem)) { +mmap_read_unlock (mm); +if (mmap_write_lock_killable (mm)) { count = -EINTR ; goto out_mm; }
@@ -1209,14 +1209,14 @@ static ssize_t clear_refs_write(struct file *file, const char __user *buf,* failed like if * get_proc_task() fails? */ -up_write (&mm->mmap_sem); +mmap_write_unlock (mm); goto out_mm; }for (vma = mm->mmap; vma; vma = vma->vm_next) { vma->vm_flags &= ~VM_SOFTDIRTY ;vma_set_page_prot (vma); } -downgrade_write (&mm->mmap_sem); +mmap_downgrade_write_lock (mm);break ; }
@@ -1229,7 +1229,7 @@ static ssize_t clear_refs_write(struct file *file, const char __user *buf,if (type ==CLEAR_REFS_SOFT_DIRTY )mmu_notifier_invalidate_range_end (&range);tlb_finish_mmu (&tlb,0 ,-1 ); -up_read (&mm->mmap_sem); +mmap_read_unlock (mm); out_mm:mmput (mm); }
@@ -1590,11 +1590,11 @@ static ssize_t pagemap_read(struct file *file, char __user *buf,/* overflow ? */ if (end < start_vaddr || end > end_vaddr) end = end_vaddr; - ret =down_read_killable (&mm->mmap_sem); + ret =mmap_read_lock_killable (mm);if (ret) goto out_free; ret =walk_page_range (mm, start_vaddr, end, &pagemap_ops, &pm); -up_read (&mm->mmap_sem); +mmap_read_unlock (mm); start_vaddr = end; len =min (count,PM_ENTRY_BYTES * pm.pos);
fs/proc/task_nommu.c +9 -9
@@ -25,7 +25,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)struct rb_node *p;unsigned long bytes =0 , sbytes =0 , slack =0 , size; -down_read (&mm->mmap_sem); +mmap_read_lock (mm);for (p =rb_first (&mm->mm_rb); p; p =rb_next (p)) { vma = rb_entry(p, struct vm_area_struct, vm_rb);
@@ -77,7 +77,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)"Shared:\t%8lu bytes\n" , bytes, slack, sbytes); -up_read (&mm->mmap_sem); +mmap_read_unlock (mm); }unsigned long task_vsize (struct mm_struct *mm)
@@ -86,12 +86,12 @@ unsigned long task_vsize(struct mm_struct *mm)struct rb_node *p;unsigned long vsize =0 ; -down_read (&mm->mmap_sem); +mmap_read_lock (mm);for (p =rb_first (&mm->mm_rb); p; p =rb_next (p)) { vma = rb_entry(p, struct vm_area_struct, vm_rb); vsize += vma->vm_end - vma->vm_start; } -up_read (&mm->mmap_sem); +mmap_read_unlock (mm);return vsize; }
@@ -104,7 +104,7 @@ unsigned long task_statm(struct mm_struct *mm,struct rb_node *p;unsigned long size =kobjsize (mm); -down_read (&mm->mmap_sem); +mmap_read_lock (mm);for (p =rb_first (&mm->mm_rb); p; p =rb_next (p)) { vma = rb_entry(p, struct vm_area_struct, vm_rb); size +=kobjsize (vma);
@@ -119,7 +119,7 @@ unsigned long task_statm(struct mm_struct *mm, >> PAGE_SHIFT; *data = (PAGE_ALIGN (mm->start_stack) - (mm->start_data &PAGE_MASK )) >>PAGE_SHIFT ; -up_read (&mm->mmap_sem); +mmap_read_unlock (mm); size >>=PAGE_SHIFT ;
Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.26.0.rc2.310.g2932bb562d-goog
Part of the diff is not shown here. View the raw message.
PATCH v3 6/10 mmap locking API: convert nested write lock sites
In reply to Michel LespinasseAdd API for nested write locks and convert the few call sites doing that.
--- arch/um/include/asm/mmu_context.h | 5 +++-- include/linux/mmap_lock.h | 11 +++++++++++ kernel/fork.c | 4 ++-- 3 files changed, 16 insertions(+), 4 deletions(-)
arch/um/include/asm/mmu_context.h +3 -2
@@ -8,6 +8,7 @@#include <linux/sched.h> #include <linux/mm_types.h> +#include <linux/mmap_lock.h> #include <asm/mmu.h>
@@ -47,9 +48,9 @@ static inline void activate_mm(struct mm_struct *old, struct mm_struct *new)* when the new ->mm is used for the first time. */ __switch_mm (&new->context.id); -down_write_nested (&new->mmap_sem,1 ); +mmap_write_lock_nested (new,1 );uml_setup_stubs (new); -mmap_write_unlock (new); +mmap_write_unlock_nested (new); } static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
include/linux/mmap_lock.h +11 -0
@@ -11,6 +11,11 @@ static inline void mmap_write_lock(struct mm_struct *mm)down_write (&mm->mmap_sem); } +static inline void mmap_write_lock_nested (struct mm_struct *mm,int subclass) +{ +down_write_nested (&mm->mmap_sem, subclass); +} +static inline int mmap_write_lock_killable (struct mm_struct *mm) {return down_write_killable (&mm->mmap_sem);
@@ -26,6 +31,12 @@ static inline void mmap_write_unlock(struct mm_struct *mm)up_write (&mm->mmap_sem); } +/* Pairs with mmap_write_lock_nested() */ +static inline void mmap_write_unlock_nested (struct mm_struct *mm) +{ +up_write (&mm->mmap_sem); +} +static inline void mmap_downgrade_write_lock (struct mm_struct *mm) {downgrade_write (&mm->mmap_sem);
kernel/fork.c +2 -2
@@ -497,7 +497,7 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm,/* * Not linked in yet - no deadlock potential: */ -down_write_nested (&mm->mmap_sem,SINGLE_DEPTH_NESTING ); +mmap_write_lock_nested (mm,SINGLE_DEPTH_NESTING );/* No ordering required: file already has been exposed. */ RCU_INIT_POINTER (mm->exe_file,get_mm_exe_file (oldmm));
@@ -612,7 +612,7 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm,/* a new mm has just been created */ retval =arch_dup_mmap (oldmm, mm); out: -mmap_write_unlock (mm); +mmap_write_unlock_nested (mm);flush_tlb_mm (oldmm);mmap_write_unlock (oldmm);dup_userfaultfd_complete (&uf);
Signature · 1 line
2.26.0.rc2.310.g2932bb562d-goog
PATCH v3 7/10 mmap locking API: add mmap_read_release() and mmap_read_unlock_non_owner()
In reply to Michel LespinasseAdd a couple APIs to allow splitting mmap_read_unlock() into two calls:
- mmap_read_release(), called by the task that had taken the mmap lock;
- mmap_read_unlock_non_owner(), called from a work queue.
These apis are used by kernel/bpf/stackmap.c only.
--- include/linux/mmap_lock.h | 10 ++++++++++ kernel/bpf/stackmap.c | 9 ++++----- 2 files changed, 14 insertions(+), 5 deletions(-)
include/linux/mmap_lock.h +10 -0
@@ -62,4 +62,14 @@ static inline void mmap_read_unlock(struct mm_struct *mm) up_read(&mm->mmap_sem); } +static inline void mmap_read_release (struct mm_struct *mm,unsigned long ip) +{ +rwsem_release (&mm->mmap_sem.dep_map, ip); +} + +static inline void mmap_read_unlock_non_owner (struct mm_struct *mm) +{ +up_read_non_owner (&mm->mmap_sem); +} +#endif /* _LINUX_MMAP_LOCK_H */
kernel/bpf/stackmap.c +4 -5
@@ -33,7 +33,7 @@ struct bpf_stack_map {/* irq_work to run up_read() for build_id lookup in nmi context */ struct stack_map_irq_work {struct irq_work irq_work; -struct rw_semaphore *sem; +struct mm_struct *mm; };static void do_up_read (struct irq_work *entry)
@@ -41,8 +41,7 @@ static void do_up_read(struct irq_work *entry)struct stack_map_irq_work *work; work = container_of(entry, struct stack_map_irq_work, irq_work); -up_read_non_owner (work->sem); - work->sem =NULL ; +mmap_read_unlock_non_owner (work->mm); } static DEFINE_PER_CPU(struct stack_map_irq_work, up_read_work);
@@ -332,14 +331,14 @@ static void stack_map_get_build_id_offset(struct bpf_stack_build_id *id_offs,if (!work) {mmap_read_unlock (current->mm); }else { - work->sem = ¤t->mm->mmap_sem; + work->mm = current->mm;irq_work_queue (&work->irq_work);/* * The irq_work will release the mmap_sem with * up_read_non_owner(). The rwsem_release() is called * here to release the lock from lockdep's perspective. */ -rwsem_release (¤t->mm->mmap_sem.dep_map, _RET_IP_); +mmap_read_release (current->mm, _RET_IP_); } }
Signature · 1 line
2.26.0.rc2.310.g2932bb562d-goog
PATCH v3 8/10 mmap locking API: add MMAP_LOCK_INITIALIZER
In reply to Michel LespinasseDefine a new initializer for the mmap locking api. Initially this just evaluates to __RWSEM_INITIALIZER as the API is defined as wrappers around rwsem.
--- arch/x86/kernel/tboot.c | 2 +- drivers/firmware/efi/efi.c | 2 +- include/linux/mmap_lock.h | 2 ++ mm/init-mm.c | 2 +- 4 files changed, 5 insertions(+), 3 deletions(-)
arch/x86/kernel/tboot.c +1 -1
@@ -90,7 +90,7 @@ static struct mm_struct tboot_mm = { .pgd = swapper_pg_dir, .mm_users = ATOMIC_INIT(2), .mm_count = ATOMIC_INIT(1), - .mmap_sem = __RWSEM_INITIALIZER(init_mm.mmap_sem), + .mmap_sem = MMAP_LOCK_INITIALIZER(init_mm.mmap_sem), .page_table_lock = __SPIN_LOCK_UNLOCKED(init_mm.page_table_lock), .mmlist = LIST_HEAD_INIT(init_mm.mmlist), };
drivers/firmware/efi/efi.c +1 -1
@@ -60,7 +60,7 @@ struct mm_struct efi_mm = { .mm_rb = RB_ROOT, .mm_users = ATOMIC_INIT(2), .mm_count = ATOMIC_INIT(1), - .mmap_sem = __RWSEM_INITIALIZER(efi_mm.mmap_sem), + .mmap_sem = MMAP_LOCK_INITIALIZER(efi_mm.mmap_sem), .page_table_lock = __SPIN_LOCK_UNLOCKED(efi_mm.page_table_lock), .mmlist = LIST_HEAD_INIT(efi_mm.mmlist), .cpu_bitmap = { [BITS_TO_LONGS(NR_CPUS)] = 0},
include/linux/mmap_lock.h +2 -0
@@ -1,6 +1,8 @@#ifndef _LINUX_MMAP_LOCK_H#define _LINUX_MMAP_LOCK_H +#define MMAP_LOCK_INITIALIZER (name) __RWSEM_INITIALIZER(name) +static inline void mmap_init_lock (struct mm_struct *mm) {init_rwsem (&mm->mmap_sem);
mm/init-mm.c +1 -1
@@ -31,7 +31,7 @@ struct mm_struct init_mm = { .pgd = swapper_pg_dir, .mm_users = ATOMIC_INIT(2), .mm_count = ATOMIC_INIT(1), - .mmap_sem = __RWSEM_INITIALIZER(init_mm.mmap_sem), + .mmap_sem = MMAP_LOCK_INITIALIZER(init_mm.mmap_sem), .page_table_lock = __SPIN_LOCK_UNLOCKED(init_mm.page_table_lock), .arg_lock = __SPIN_LOCK_UNLOCKED(init_mm.arg_lock), .mmlist = LIST_HEAD_INIT(init_mm.mmlist),
Signature · 1 line
2.26.0.rc2.310.g2932bb562d-goog
PATCH v3 9/10 mmap locking API: use lockdep_assert_held
In reply to Michel LespinasseUse lockdep_assert_held when asserting that mmap_sem is held.
Using this instead of rwsem_is_locked makes the assertions more tolerant of future changes to the lock type.
--- fs/userfaultfd.c | 6 +++--- mm/gup.c | 2 +- mm/memory.c | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-)
fs/userfaultfd.c +3 -3
@@ -234,7 +234,7 @@ static inline bool userfaultfd_huge_must_wait(struct userfaultfd_ctx *ctx,pte_t *ptep, pte;bool ret = true; -VM_BUG_ON (!rwsem_is_locked (&mm->mmap_sem)); +lockdep_assert_held (&mm->mmap_sem); ptep =huge_pte_offset (mm, address,vma_mmu_pagesize (vma));
@@ -286,7 +286,7 @@ static inline bool userfaultfd_must_wait(struct userfaultfd_ctx *ctx,pte_t *pte;bool ret = true; -VM_BUG_ON (!rwsem_is_locked (&mm->mmap_sem)); +lockdep_assert_held (&mm->mmap_sem); pgd =pgd_offset (mm, address);if (!pgd_present (*pgd))
@@ -376,7 +376,7 @@ vm_fault_t handle_userfault(struct vm_fault *vmf, unsigned long reason)* Coredumping runs without mmap_sem so we can only check that * the mmap_sem is held, if PF_DUMPCORE was not set. */ -WARN_ON_ONCE (!rwsem_is_locked (&mm->mmap_sem)); +lockdep_assert_held (&mm->mmap_sem); ctx = vmf->vma->vm_userfaultfd_ctx.ctx;if (!ctx)
mm/gup.c +1 -1
@@ -1154,7 +1154,7 @@ long populate_vma_page_range(struct vm_area_struct *vma,VM_BUG_ON (end & ~PAGE_MASK );VM_BUG_ON_VMA (start < vma->vm_start, vma);VM_BUG_ON_VMA (end > vma->vm_end, vma); -VM_BUG_ON_MM (!rwsem_is_locked (&mm->mmap_sem), mm); +lockdep_assert_held (&mm->mmap_sem); gup_flags =FOLL_TOUCH |FOLL_POPULATE |FOLL_MLOCK ;if (vma->vm_flags &VM_LOCKONFAULT )
mm/memory.c +1 -1
@@ -1202,7 +1202,7 @@ static inline unsigned long zap_pud_range(struct mmu_gather *tlb, next =pud_addr_end (addr, end);if (pud_trans_huge (*pud) ||pud_devmap (*pud)) {if (next - addr !=HPAGE_PUD_SIZE ) { -VM_BUG_ON_VMA (!rwsem_is_locked (&tlb->mm->mmap_sem), vma); +lockdep_assert_held (&tlb->mm->mmap_sem);split_huge_pud (vma, pud, addr); }else if (zap_huge_pud (tlb, vma, pud, addr)) goto next;
Signature · 1 line
2.26.0.rc2.310.g2932bb562d-goog
PATCH v3 10/10 mmap locking API: rename mmap_sem to mmap_lock
In reply to Michel LespinasseRename the mmap_sem field to mmap_lock. Any new uses of this lock should now go through the new mmap locking api. The mmap_lock is still implemented as a rwsem, though this could change in the future.
--- arch/ia64/mm/fault.c | 4 ++-- arch/x86/events/core.c | 4 ++-- arch/x86/kernel/tboot.c | 2 +- arch/x86/mm/fault.c | 2 +- drivers/firmware/efi/efi.c | 2 +- drivers/gpu/drm/etnaviv/etnaviv_gem.c | 2 +- fs/userfaultfd.c | 6 +++--- include/linux/mm_types.h | 2 +- include/linux/mmap_lock.h | 28 +++++++++++++-------------- mm/gup.c | 2 +- mm/hmm.c | 2 +- mm/init-mm.c | 2 +- mm/memory.c | 4 ++-- mm/mmap.c | 4 ++-- mm/mmu_notifier.c | 18 ++++++++--------- mm/pagewalk.c | 15 +++++++------- mm/util.c | 4 ++-- 17 files changed, 52 insertions(+), 51 deletions(-)
arch/ia64/mm/fault.c +2 -2
@@ -70,8 +70,8 @@ ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *re mask = ((((isr >>IA64_ISR_X_BIT ) &1UL ) <<VM_EXEC_BIT ) | (((isr >>IA64_ISR_W_BIT ) &1UL ) <<VM_WRITE_BIT )); -/* mmap_sem is performance critical.... */ -prefetchw (&mm->mmap_sem); +/* mmap_lock is performance critical.... */ +prefetchw (&mm->mmap_lock);/* * If we're in an interrupt or have no user context, we must not take the fault..
arch/x86/events/core.c +2 -2
@@ -2179,10 +2179,10 @@ static void x86_pmu_event_mapped(struct perf_event *event, struct mm_struct *mm)* userspace with CR4.PCE clear while another task is still * doing on_each_cpu_mask() to propagate CR4.PCE. * -* For now, this can't happen because all callers hold mmap_sem +* For now, this can't happen because all callers hold mmap_lock * for write. If this changes, we'll need a different solution. */ -lockdep_assert_held_write (&mm->mmap_sem); +lockdep_assert_held_write (&mm->mmap_lock);if (atomic_inc_return (&mm->context.perf_rdpmc_allowed) ==1 )on_each_cpu_mask (mm_cpumask (mm), refresh_pce,NULL ,1 );
arch/x86/kernel/tboot.c +1 -1
@@ -90,7 +90,7 @@ static struct mm_struct tboot_mm = { .pgd = swapper_pg_dir, .mm_users = ATOMIC_INIT(2), .mm_count = ATOMIC_INIT(1), - .mmap_sem = MMAP_LOCK_INITIALIZER(init_mm.mmap_sem), + .mmap_lock = MMAP_LOCK_INITIALIZER(init_mm.mmap_lock), .page_table_lock = __SPIN_LOCK_UNLOCKED(init_mm.page_table_lock), .mmlist = LIST_HEAD_INIT(init_mm.mmlist), };
arch/x86/mm/fault.c +1 -1
@@ -1526,7 +1526,7 @@ dotraplinkage void do_page_fault(struct pt_regs *regs, unsigned long hw_error_code, unsigned long address) { - prefetchw(¤t->mm->mmap_sem); + prefetchw(¤t->mm->mmap_lock);trace_page_fault_entries (regs, hw_error_code, address);if (unlikely (kmmio_fault (regs, address)))
drivers/firmware/efi/efi.c +1 -1
@@ -60,7 +60,7 @@ struct mm_struct efi_mm = { .mm_rb = RB_ROOT, .mm_users = ATOMIC_INIT(2), .mm_count = ATOMIC_INIT(1), - .mmap_sem = MMAP_LOCK_INITIALIZER(efi_mm.mmap_sem), + .mmap_lock = MMAP_LOCK_INITIALIZER(efi_mm.mmap_lock), .page_table_lock = __SPIN_LOCK_UNLOCKED(efi_mm.page_table_lock), .mmlist = LIST_HEAD_INIT(efi_mm.mmlist), .cpu_bitmap = { [BITS_TO_LONGS(NR_CPUS)] = 0},
drivers/gpu/drm/etnaviv/etnaviv_gem.c +1 -1
@@ -661,7 +661,7 @@ static int etnaviv_gem_userptr_get_pages(struct etnaviv_gem_object *etnaviv_obj)struct etnaviv_gem_userptr *userptr = &etnaviv_obj->userptr;int ret, pinned =0 , npages = etnaviv_obj->base.size >>PAGE_SHIFT ; -might_lock_read (¤t->mm->mmap_sem); +might_lock_read (¤t->mm->mmap_lock);if (userptr->mm != current->mm)return -EPERM ;
fs/userfaultfd.c +3 -3
@@ -234,7 +234,7 @@ static inline bool userfaultfd_huge_must_wait(struct userfaultfd_ctx *ctx,pte_t *ptep, pte;bool ret = true; -lockdep_assert_held (&mm->mmap_sem); +lockdep_assert_held (&mm->mmap_lock); ptep =huge_pte_offset (mm, address,vma_mmu_pagesize (vma));
@@ -286,7 +286,7 @@ static inline bool userfaultfd_must_wait(struct userfaultfd_ctx *ctx,pte_t *pte;bool ret = true; -lockdep_assert_held (&mm->mmap_sem); +lockdep_assert_held (&mm->mmap_lock); pgd =pgd_offset (mm, address);if (!pgd_present (*pgd))
@@ -376,7 +376,7 @@ vm_fault_t handle_userfault(struct vm_fault *vmf, unsigned long reason)* Coredumping runs without mmap_sem so we can only check that * the mmap_sem is held, if PF_DUMPCORE was not set. */ -lockdep_assert_held (&mm->mmap_sem); +lockdep_assert_held (&mm->mmap_lock); ctx = vmf->vma->vm_userfaultfd_ctx.ctx;if (!ctx)
include/linux/mm_types.h +1 -1
@@ -431,7 +431,7 @@ struct mm_struct {spinlock_t page_table_lock;/* Protects page tables and some * counters */ -struct rw_semaphore mmap_sem; +struct rw_semaphore mmap_lock;struct list_head mmlist;/* List of maybe swapped mm's. These * are globally strung together off
include/linux/mmap_lock.h +14 -14
@@ -5,73 +5,73 @@static inline void mmap_init_lock (struct mm_struct *mm) { -init_rwsem (&mm->mmap_sem); +init_rwsem (&mm->mmap_lock); }static inline void mmap_write_lock (struct mm_struct *mm) { -down_write (&mm->mmap_sem); +down_write (&mm->mmap_lock); }static inline void mmap_write_lock_nested (struct mm_struct *mm,int subclass) { -down_write_nested (&mm->mmap_sem, subclass); +down_write_nested (&mm->mmap_lock, subclass); }static inline int mmap_write_lock_killable (struct mm_struct *mm) { -return down_write_killable (&mm->mmap_sem); +return down_write_killable (&mm->mmap_lock); }static inline bool mmap_write_trylock (struct mm_struct *mm) { -return down_write_trylock (&mm->mmap_sem) !=0 ; +return down_write_trylock (&mm->mmap_lock) !=0 ; }static inline void mmap_write_unlock (struct mm_struct *mm) { -up_write (&mm->mmap_sem); +up_write (&mm->mmap_lock); }/* Pairs with mmap_write_lock_nested() */ static inline void mmap_write_unlock_nested (struct mm_struct *mm) { -up_write (&mm->mmap_sem); +up_write (&mm->mmap_lock); }static inline void mmap_downgrade_write_lock (struct mm_struct *mm) { -downgrade_write (&mm->mmap_sem); +downgrade_write (&mm->mmap_lock); }static inline void mmap_read_lock (struct mm_struct *mm) { -down_read (&mm->mmap_sem); +down_read (&mm->mmap_lock); }static inline int mmap_read_lock_killable (struct mm_struct *mm) { -return down_read_killable (&mm->mmap_sem); +return down_read_killable (&mm->mmap_lock); }static inline bool mmap_read_trylock (struct mm_struct *mm) { -return down_read_trylock (&mm->mmap_sem) !=0 ; +return down_read_trylock (&mm->mmap_lock) !=0 ; }static inline void mmap_read_unlock (struct mm_struct *mm) { -up_read (&mm->mmap_sem); +up_read (&mm->mmap_lock); }static inline void mmap_read_release (struct mm_struct *mm,unsigned long ip) { -rwsem_release (&mm->mmap_sem.dep_map, ip); +rwsem_release (&mm->mmap_lock.dep_map, ip); }static inline void mmap_read_unlock_non_owner (struct mm_struct *mm) { -up_read_non_owner (&mm->mmap_sem); +up_read_non_owner (&mm->mmap_lock); }#endif /* _LINUX_MMAP_LOCK_H */
mm/gup.c +1 -1
@@ -1154,7 +1154,7 @@ long populate_vma_page_range(struct vm_area_struct *vma,VM_BUG_ON (end & ~PAGE_MASK );VM_BUG_ON_VMA (start < vma->vm_start, vma);VM_BUG_ON_VMA (end > vma->vm_end, vma); -lockdep_assert_held (&mm->mmap_sem); +lockdep_assert_held (&mm->mmap_lock); gup_flags =FOLL_TOUCH |FOLL_POPULATE |FOLL_MLOCK ;if (vma->vm_flags &VM_LOCKONFAULT )
mm/hmm.c +1 -1
@@ -681,7 +681,7 @@ long hmm_range_fault(struct hmm_range *range, unsigned int flags)struct mm_struct *mm = range->notifier->mm;int ret; -lockdep_assert_held (&mm->mmap_sem); +lockdep_assert_held (&mm->mmap_lock); do { /* If range is no longer valid force retry. */
mm/init-mm.c +1 -1
@@ -31,7 +31,7 @@ struct mm_struct init_mm = { .pgd = swapper_pg_dir, .mm_users = ATOMIC_INIT(2), .mm_count = ATOMIC_INIT(1), - .mmap_sem = MMAP_LOCK_INITIALIZER(init_mm.mmap_sem), + .mmap_lock = MMAP_LOCK_INITIALIZER(init_mm.mmap_lock), .page_table_lock = __SPIN_LOCK_UNLOCKED(init_mm.page_table_lock), .arg_lock = __SPIN_LOCK_UNLOCKED(init_mm.arg_lock), .mmlist = LIST_HEAD_INIT(init_mm.mmlist),
mm/memory.c +2 -2
@@ -1202,7 +1202,7 @@ static inline unsigned long zap_pud_range(struct mmu_gather *tlb, next =pud_addr_end (addr, end);if (pud_trans_huge (*pud) ||pud_devmap (*pud)) {if (next - addr !=HPAGE_PUD_SIZE ) { -lockdep_assert_held (&tlb->mm->mmap_sem); +lockdep_assert_held (&tlb->mm->mmap_lock);split_huge_pud (vma, pud, addr); }else if (zap_huge_pud (tlb, vma, pud, addr)) goto next;
@@ -4648,7 +4648,7 @@ void __might_fault(const char *file, int line)__might_sleep (file, line,0 );#if defined(CONFIG_DEBUG_ATOMIC_SLEEP )if (current->mm) -might_lock_read (¤t->mm->mmap_sem); +might_lock_read (¤t->mm->mmap_lock);#endif }EXPORT_SYMBOL (__might_fault);
mm/mmap.c +2 -2
@@ -3450,7 +3450,7 @@ static void vm_lock_anon_vma(struct mm_struct *mm, struct anon_vma *anon_vma)* The LSB of head.next can't change from under us * because we hold the mm_all_locks_mutex. */ -down_write_nest_lock (&anon_vma->root->rwsem, &mm->mmap_sem); +down_write_nest_lock (&anon_vma->root->rwsem, &mm->mmap_lock);/* * We can safely modify head.next after taking the * anon_vma->root->rwsem. If some other vma in this mm shares
@@ -3480,7 +3480,7 @@ static void vm_lock_mapping(struct mm_struct *mm, struct address_space *mapping)*/ if (test_and_set_bit (AS_MM_ALL_LOCKS , &mapping->flags))BUG (); -down_write_nest_lock (&mapping->i_mmap_rwsem, &mm->mmap_sem); +down_write_nest_lock (&mapping->i_mmap_rwsem, &mm->mmap_lock); } }
mm/mmu_notifier.c +9 -9
@@ -599,7 +599,7 @@ void __mmu_notifier_invalidate_range(struct mm_struct *mm, }/* -* Same as mmu_notifier_register but here the caller must hold the mmap_sem in +* Same as mmu_notifier_register but here the caller must hold the mmap_lock in * write mode. A NULL mn signals the notifier is being registered for itree * mode. */
@@ -609,7 +609,7 @@ int __mmu_notifier_register(struct mmu_notifier *subscription,struct mmu_notifier_subscriptions *subscriptions =NULL ;int ret; -lockdep_assert_held_write (&mm->mmap_sem); +lockdep_assert_held_write (&mm->mmap_lock);BUG_ON (atomic_read (&mm->mm_users) <=0 );if (IS_ENABLED (CONFIG_LOCKDEP )) {
@@ -623,7 +623,7 @@ int __mmu_notifier_register(struct mmu_notifier *subscription,/* * kmalloc cannot be called under mm_take_all_locks(), but we * know that mm->notifier_subscriptions can't change while we -* hold the write side of the mmap_sem. +* hold the write side of the mmap_lock. */ subscriptions =kzalloc (sizeof (struct mmu_notifier_subscriptions ),GFP_KERNEL );
@@ -655,7 +655,7 @@ int __mmu_notifier_register(struct mmu_notifier *subscription,* readers. acquire can only be used while holding the mmgrab or * mmget, and is safe because once created the * mmu_notifier_subscriptions is not freed until the mm is destroyed. -* As above, users holding the mmap_sem or one of the +* As above, users holding the mmap_lock or one of the * mm_take_all_locks() do not need to use acquire semantics. */ if (subscriptions)
@@ -689,7 +689,7 @@ EXPORT_SYMBOL_GPL(__mmu_notifier_register);* @mn: The notifier to attach * @mm: The mm to attach the notifier to * -* Must not hold mmap_sem nor any other VM related lock when calling +* Must not hold mmap_lock nor any other VM related lock when calling * this registration function. Must also ensure mm_users can't go down * to zero while this runs to avoid races with mmu_notifier_release, * so mm has to be current->mm or the mm should be pinned safely such
@@ -750,7 +750,7 @@ find_get_mmu_notifier(struct mm_struct *mm, const struct mmu_notifier_ops *ops)* are the same. * * Each call to mmu_notifier_get() must be paired with a call to -* mmu_notifier_put(). The caller must hold the write side of mm->mmap_sem. +* mmu_notifier_put(). The caller must hold the write side of mm->mmap_lock. * * While the caller has a mmu_notifier get the mm pointer will remain valid, * and can be converted to an active mm pointer via mmget_not_zero().
@@ -761,7 +761,7 @@ struct mmu_notifier *mmu_notifier_get_locked(const struct mmu_notifier_ops *ops,struct mmu_notifier *subscription;int ret; -lockdep_assert_held_write (&mm->mmap_sem); +lockdep_assert_held_write (&mm->mmap_lock);if (mm->notifier_subscriptions) { subscription =find_get_mmu_notifier (mm, ops);
@@ -983,7 +983,7 @@ int mmu_interval_notifier_insert(struct mmu_interval_notifier *interval_sub,struct mmu_notifier_subscriptions *subscriptions;int ret; -might_lock (&mm->mmap_sem); +might_lock (&mm->mmap_lock); subscriptions =smp_load_acquire (&mm->notifier_subscriptions);if (!subscriptions || !subscriptions->has_itree) {
@@ -1006,7 +1006,7 @@ int mmu_interval_notifier_insert_locked( mm->notifier_subscriptions;int ret; -lockdep_assert_held_write (&mm->mmap_sem); +lockdep_assert_held_write (&mm->mmap_lock);if (!subscriptions || !subscriptions->has_itree) { ret =__mmu_notifier_register (NULL , mm);
mm/pagewalk.c +8 -7
@@ -373,8 +373,9 @@ static int __walk_page_range(unsigned long start, unsigned long end,* caller-specific data to callbacks, @private should be helpful. * * Locking: -* Callers of walk_page_range() and walk_page_vma() should hold @mm->mmap_sem, -* because these function traverse vma list and/or access to vma's data. +* Callers of walk_page_range() and walk_page_vma() should hold +* @mm->mmap_lock, because these function traverse the vma list +* and/or access the vma's data. */ int walk_page_range(struct mm_struct *mm, unsigned long start, unsigned long end, const struct mm_walk_ops *ops,
@@ -395,7 +396,7 @@ int walk_page_range(struct mm_struct *mm, unsigned long start,if (!walk.mm)return -EINVAL ; -lockdep_assert_held (&walk.mm->mmap_sem); +lockdep_assert_held (&walk.mm->mmap_lock); vma =find_vma (walk.mm, start); do {
@@ -453,7 +454,7 @@ int walk_page_range_novma(struct mm_struct *mm, unsigned long start,if (start >= end || !walk.mm)return -EINVAL ; -lockdep_assert_held (&walk.mm->mmap_sem); +lockdep_assert_held (&walk.mm->mmap_lock);return __walk_page_range (start, end, &walk); }
@@ -472,7 +473,7 @@ int walk_page_vma(struct vm_area_struct *vma, const struct mm_walk_ops *ops,if (!walk.mm)return -EINVAL ; -lockdep_assert_held (&walk.mm->mmap_sem); +lockdep_assert_held (&walk.mm->mmap_lock); err =walk_page_test (vma->vm_start, vma->vm_end, &walk);if (err >0 )
@@ -498,11 +499,11 @@ int walk_page_vma(struct vm_area_struct *vma, const struct mm_walk_ops *ops,* Also see walk_page_range() for additional information. * * Locking: -* This function can't require that the struct mm_struct::mmap_sem is held, +* This function can't require that the struct mm_struct::mmap_lock is held, * since @mapping may be mapped by multiple processes. Instead * @mapping->i_mmap_rwsem must be held. This might have implications in the * callbacks, and it's up tho the caller to ensure that the -* struct mm_struct::mmap_sem is not needed. +* struct mm_struct::mmap_lock is not needed. * * Also this means that a caller can't rely on the struct * vm_area_struct::vm_flags to be constant across a call,
mm/util.c +2 -2
@@ -425,7 +425,7 @@ void arch_pick_mmap_layout(struct mm_struct *mm, struct rlimit *rlim_stack)* @bypass_rlim: %true if checking RLIMIT_MEMLOCK should be skipped * * Assumes @task and @mm are valid (i.e. at least one reference on each), and -* that mmap_sem is held as writer. +* that mmap_lock is held as writer. * * Return: * * 0 on success
@@ -437,7 +437,7 @@ int __account_locked_vm(struct mm_struct *mm, unsigned long pages, bool inc,unsigned long locked_vm, limit;int ret =0 ; -lockdep_assert_held_write (&mm->mmap_sem); +lockdep_assert_held_write (&mm->mmap_lock); locked_vm = mm->locked_vm;if (inc) {
Signature · 1 line
2.26.0.rc2.310.g2932bb562d-goog
Re: [PATCH v3 05/10] mmap locking API: convert mmap_sem call sites missed by coccinelle
In reply to Michel LespinasseQuoted 2 lines
Convert the last few remaining
mmap_semrwsem calls to use the new mmap locking API. These were missed by coccinelle for some reason
Will the clarification of this software situation become more interesting?
Quoted 2 lines
(I think coccinelle does not support some of the preprocessor constructs in these files ?)
I suggest to omit this information from the final change description. Would you like to help any more to find nicer solutions for remaining open issues?
Regards,
Markus
Re: [PATCH v3 05/10] mmap locking API: convert mmap_sem call sites missed by coccinelle
Hi Markus,
Quoted 11 lines · Markus Elfring
Quoted 2 lines
Convert the last few remaining
mmap_semrwsem calls to use the new mmap locking API. These were missed by coccinelle for some reasonWill the clarification of this software situation become more interesting?
Quoted 2 lines
(I think coccinelle does not support some of the preprocessor constructs in these files ?)
I suggest to omit this information from the final change description. Would you like to help any more to find nicer solutions for remaining open issues?
So, from a practical perspective I think coccinelle has filled its purpose for me - it got 99% of the job done, and I had to do the last 1% by hand which is not ideal, but really not too bad either. Also, by using coccinelle I think reviewers can appreciate that the change is purely mechanical, and reproduce it on their end if needed, which facilitates the review process greatly.
I would be interested to find out why coccinelle wasn't able to do the last 1%, but only as part of a long-term learning process on getting better with coccinelle - I don't consider it a blocker for short-term progress on this patchset.
Signature · 2 lines
Michel "Walken" Lespinasse A program is never fully debugged until the last user dies.
Re: [v3 05/10] mmap locking API: convert mmap_sem call sites missed by coccinelle
Quoted 3 lines
I would be interested to find out why coccinelle wasn't able to do the last 1%, but only as part of a long-term learning process on getting better with coccinelle - …
How will corresponding software development resources evolve?
Regards,
Markus
Re: [v3 05/10] mmap locking API: convert mmap_sem call sites missed by coccinelle
Quoted 5 lines · Markus Elfring
Quoted 3 lines
I would be interested to find out why coccinelle wasn't able to do the last 1%, but only as part of a long-term learning process on getting better with coccinelle - …
How will corresponding software development resources evolve?
I don't think I understand the question, or, actually, are you asking me or the coccinelle developers ?
Signature · 2 lines
Michel "Walken" Lespinasse A program is never fully debugged until the last user dies.
Re: [PATCH v3 01/10] mmap locking API: initial implementation as rwsem wrappers (Michel Lespinasse)
In reply to Michel LespinasseQuoted 78 lines · On 2020-03-27T15:50:53-07:00 Michel Lespinasse <[email protected]> wrote:
This change wraps the existing
mmap_semrelated rwsem calls into a new mmap locking API. There are two justifications for the new API:- At first, it provides an easy hooking point to instrument
mmap_semlocking latencies independently of any other rwsems.- In the future, it may be a starting point for replacing the rwsem implementation with a different one, such as range locks.
Signed-off-by Michel Lespinasse <[email protected]>--- include/linux/mm.h | 1 + include/linux/mmap_lock.h | 54 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 include/linux/mmap_lock.hinclude/linux/mm.h +1
-0@@ -15,6 +15,7 @@#include <linux/atomic.h> #include <linux/debug_locks.h> #include <linux/mm_types.h> +#include <linux/mmap_lock.h> #include <linux/range.h> #include <linux/pfn.h> #include <linux/percpu-refcount.h> include/linux/mmap_lock.h new file +44
-0@@ -0,0 +1,54 @@ +#ifndef _LINUX_MMAP_LOCK_H +#define _LINUX_MMAP_LOCK_H + +static inline void mmap_init_lock (struct mm_struct *mm) +{ +init_rwsem (&mm->mmap_sem); +} + +static inline void mmap_write_lock (struct mm_struct *mm) +{ +down_write (&mm->mmap_sem); +} + +static inline int mmap_write_lock_killable (struct mm_struct *mm) +{ +return down_write_killable (&mm->mmap_sem); +} + +static inline bool mmap_write_trylock (struct mm_struct *mm) +{ +return down_write_trylock (&mm->mmap_sem) !=0 ; +} + +static inline void mmap_write_unlock (struct mm_struct *mm) +{ +up_write (&mm->mmap_sem); +} + +static inline void mmap_downgrade_write_lock (struct mm_struct *mm) +{ +downgrade_write (&mm->mmap_sem); +} + +static inline void mmap_read_lock (struct mm_struct *mm) +{ +down_read (&mm->mmap_sem); +} + +static inline int mmap_read_lock_killable (struct mm_struct *mm) +{ +return down_read_killable (&mm->mmap_sem); +} + +static inline bool mmap_read_trylock (struct mm_struct *mm)
include/linux/mmap_lock.h line 54
Quoted 10 lines
include/linux/mmap_lock.h new file +10
-0+{ +return down_read_trylock (&mm->mmap_sem) !=0 ; +} + +static inline void mmap_read_unlock (struct mm_struct *mm) +{ +up_read (&mm->mmap_sem); +} + +#endif /* _LINUX_MMAP_LOCK_H */
Quoted 3 lines
Signature · 1 line
2.26.0.rc2.310.g2932bb562d-goog
Re: [v3 05/10] mmap locking API: convert mmap_sem call sites missed by coccinelle
In reply to Michel LespinasseQuoted 7 lines
Quoted 5 lines
Quoted 3 lines
I would be interested to find out why coccinelle wasn't able to do the last 1%, but only as part of a long-term learning process on getting better with coccinelle - …
How will corresponding software development resources evolve?
I don't think I understand the question,
Various aspects can be reconsidered.
Quoted 1 line
or, actually, are you asking me or the coccinelle developers ?
I am curious how much the change interests will grow by involved contributors and organisations.
Would you like to discuss affected implementation details any further?
Regards,
Markus
Re: [v3 05/10] mmap locking API: Checking the Coccinelle software
In reply to Michel LespinasseQuoted 4 lines
Quoted 1 line
How will corresponding software development resources evolve?
I don't think I understand the question, or, actually, are you asking me or the coccinelle developers ?
I hope that another communication approach can eventually increase the chances for a better common understanding of development challenges.
The code from a mentioned source file can be reduced to the following test file.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/mips/mm/fault.c?id=69c5eea3128e775fd3c70ecf0098105d96dee330#n34
// deleted part
static void __kprobes __do_page_fault(struct pt_regs *regs, unsigned long write,
unsigned long address)
{
struct vm_area_struct * vma = NULL;
struct task_struct *tsk = current;
struct mm_struct *mm = tsk->mm;
// deleted part
retry:
down_read(&mm->mmap_sem);
vma = find_vma(mm, address);
if (!vma)
goto bad_area;// deleted part
}
// deleted part
Application of the software “Coccinelle 1.0.8-00029-ga549b9f0” (OCaml 4.10.0)
elfring@Sonne:~/Projekte/Coccinelle/Probe> spatch --parse-c do_page_fault-excerpt3.c …
NB total files = 1; perfect = 1; pbs = 0; timeout = 0; =========> 100% nb good = 15, nb passed = 1 =========> 6.25% passed
nb good = 15, nb bad = 0 =========> 100.00% good or passed
The discussed transformation approach can also be reduced for a test to the following script for the semantic patch language.
@replacement@
expression x;
@@
-down_read
+mmap_read_lock
(
- &
x
- ->mmap_sem
)
elfring@Sonne:~/Projekte/Coccinelle/Probe> spatch use_mmap_locking_API_3.cocci do_page_fault-excerpt3.c
The desired diff is not generated so far.
How would you like to fix this situation?
Regards,
Markus
Re: [Cocci] [v3 05/10] mmap locking API: Checking the Coccinelle software
Quoted 54 lines · Markus Elfring
Quoted 4 lines
Quoted 1 line
How will corresponding software development resources evolve?
I don't think I understand the question, or, actually, are you asking me or the coccinelle developers ?
I hope that another communication approach can eventually increase the chances for a better common understanding of development challenges.
The code from a mentioned source file can be reduced to the following test file.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/mips/mm/fault.c?id=69c5eea3128e775fd3c70ecf0098105d96dee330#n34// deleted part
static void__kprobes__do_page_fault(structpt_regs*regs, unsigned long write,
unsigned long address){ struct vm_area_struct * vma = NULL; struct task_struct *tsk = current; struct mm_struct *mm = tsk->mm; // deleted part retry: down_read(&mm->mmap_sem); vma = find_vma(mm, address); if (!vma) goto bad_area;// deleted part
}
// deleted partApplication of the software “Coccinelle 1.0.8-00029-ga549b9f0” (OCaml 4.10.0)
elfring@Sonne:~/Projekte/Coccinelle/Probe> spatch --parse-c
do_page_fault-excerpt3.c…
NB total files = 1; perfect = 1; pbs = 0; timeout = 0; =========> 100% nb good = 15, nb passed = 1 =========> 6.25% passed
nb good = 15, nb bad = 0 =========> 100.00% good or passedThe discussed transformation approach can also be reduced for a test to the following script for the semantic patch language.
@replacement@
expression x;
@@(quoted diff) +1
-3-down_read +mmap_read_lock ( - & x - ->mmap_sem )
Quoted 5 lines
elfring@Sonne:~/Projekte/Coccinelle/Probe> spatch
use_mmap_locking_API_3.coccido_page_fault-excerpt3.cThe desired diff is not generated so far.
How would you like to fix this situation?
Who exactly do you think "you" is? I will look at it, but it is not very polite to ask a user of Coccinelle such a question.
julia
Quoted 8 lines
Regards,
Markus
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
Re: [Cocci] [v3 05/10] mmap locking API: Checking the Coccinelle software
Quoted 3 lines
Quoted 1 line
How would you like to fix this situation?
Who exactly do you think "you" is?
Every contributor with helpful software development resources for this issue.
Quoted 1 line
I will look at it,
Thanks for another promising feedback.
Quoted 1 line
but it is not very polite to ask a user of Coccinelle such a question.
We come along different views for the handling of such a bug report.
Regards,
Markus
Re: [Cocci] [v3 05/10] mmap locking API: Checking the Coccinelle software
In reply to Markus ElfringQuoted 54 lines · Markus Elfring
Quoted 4 lines
Quoted 1 line
How will corresponding software development resources evolve?
I don't think I understand the question, or, actually, are you asking me or the coccinelle developers ?
I hope that another communication approach can eventually increase the chances for a better common understanding of development challenges.
The code from a mentioned source file can be reduced to the following test file.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/mips/mm/fault.c?id=69c5eea3128e775fd3c70ecf0098105d96dee330#n34// deleted part
static void__kprobes__do_page_fault(structpt_regs*regs, unsigned long write,
unsigned long address){ struct vm_area_struct * vma = NULL; struct task_struct *tsk = current; struct mm_struct *mm = tsk->mm; // deleted part retry: down_read(&mm->mmap_sem); vma = find_vma(mm, address); if (!vma) goto bad_area;// deleted part
}
// deleted partApplication of the software “Coccinelle 1.0.8-00029-ga549b9f0” (OCaml 4.10.0)
elfring@Sonne:~/Projekte/Coccinelle/Probe> spatch --parse-c
do_page_fault-excerpt3.c…
NB total files = 1; perfect = 1; pbs = 0; timeout = 0; =========> 100% nb good = 15, nb passed = 1 =========> 6.25% passed
nb good = 15, nb bad = 0 =========> 100.00% good or passedThe discussed transformation approach can also be reduced for a test to the following script for the semantic patch language.
@replacement@
expression x;
@@(quoted diff) +1
-3-down_read +mmap_read_lock ( - & x - ->mmap_sem )
Quoted 5 lines
elfring@Sonne:~/Projekte/Coccinelle/Probe> spatch
use_mmap_locking_API_3.coccido_page_fault-excerpt3.cThe desired diff is not generated so far.
How would you like to fix this situation?
The problem is due to a preceding goto where the destination is expressed as a macro name. Maybe there should be a warning in this case.
julia
Quoted 8 lines
Regards,
Markus
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
Re: [Cocci] [v3 05/10] mmap locking API: Checking the Coccinelle software
In reply to Markus ElfringQuoted 35 lines
// deleted part
retry:down_read(&mm->mmap_sem); vma = find_vma(mm, address); if (!vma) goto bad_area;// deleted part
}
// deleted partApplication of the software “Coccinelle 1.0.8-00029-ga549b9f0” (OCaml 4.10.0)
elfring@Sonne:~/Projekte/Coccinelle/Probe> spatch --parse-c
do_page_fault-excerpt3.c…
NB total files = 1; perfect = 1; pbs = 0; timeout = 0; =========> 100% nb good = 15, nb passed = 1 =========> 6.25% passed
nb good = 15, nb bad = 0 =========> 100.00% good or passedThe discussed transformation approach can also be reduced for a test to the following script for the semantic patch language.
@replacement@
expression x;
@@(quoted diff) +1
-3-down_read +mmap_read_lock ( - & x - ->mmap_sem )
Quoted 5 lines
elfring@Sonne:~/Projekte/Coccinelle/Probe> spatch
use_mmap_locking_API_3.coccido_page_fault-excerpt3.cThe desired diff is not generated so far.
How would you like to fix this situation?
The problem can be seen with the --debug option:
FLOW: can't jump to VMALLOC_FAULT_TARGET: because we can't find this label
It's not apparent with the --parse-c option because it's not a parsing problem.
julia
Re: [Cocci] [v3 05/10] mmap locking API: Checking the Coccinelle software
Quoted 5 lines
The problem can be seen with the --debug option:
FLOW: can't jump to
VMALLOC_FAULT_TARGET: because we can't find this labelIt's not apparent with the --parse-c option because it's not a parsing problem.
Thanks for such information.
Can the example be transformed even if extra source code was intentionally deleted for the easier clarification of the shown software test?
Regards,
Markus
Re: [v3 05/10] mmap locking API: Improving the Coccinelle software
In reply to Michel LespinasseQuoted 4 lines
Quoted 1 line
How will corresponding software development resources evolve?
I don't think I understand the question, or, actually, are you asking me or the coccinelle developers ?
I hope that more development challenges will be picked up.
The code from a mentioned source file can be reduced to the following test file.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/x86/kvm/mmu/paging_tmpl.h?id=7111951b8d4973bda27ff663f2cf18b663d15b48#n122
// deleted part
static inline int FNAME(is_present_gpte)(unsigned long pte) {
#if PTTYPE != PTTYPE_EPT return pte & PT_PRESENT_MASK; #else return pte & 7;
#endif
}
// deleted part
Application of the software “Coccinelle 1.0.8-00029-ga549b9f0” (OCaml 4.10.0)
elfring@Sonne:~/Projekte/Coccinelle/Probe> spatch --parse-c paging_tmpl-excerpt1.h …
(ONCE) CPP-MACRO: found known macro = FNAME
…
parse error
= File "paging_tmpl-excerpt1.h", line 2, column 41, charpos = 57
around = 'unsigned',
…
BAD:!!!!! static inline int FNAME(is_present_gpte)(unsigned long pte) …
NB total files = 1; perfect = 0; pbs = 1; timeout = 0; =========> 0% nb good = 1, nb passed = 1 =========> 10.00% passed
nb good = 1, nb bad = 8 =========> 20.00% good or passed
How would you like to improve the affected software areas?
Regards,
Markus
Re: [Cocci] [v3 05/10] mmap locking API: Improving the Coccinelle software
Quoted 40 lines · Markus Elfring
Quoted 4 lines
Quoted 1 line
How will corresponding software development resources evolve?
I don't think I understand the question, or, actually, are you asking me or the coccinelle developers ?
I hope that more development challenges will be picked up.
The code from a mentioned source file can be reduced to the following test file.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/x86/kvm/mmu/paging_tmpl.h?id=7111951b8d4973bda27ff663f2cf18b663d15b48#n122// deleted part
static inline int FNAME(is_present_gpte)(unsigned long pte) {#if PTTYPE != PTTYPE_EPT return pte & PT_PRESENT_MASK; #else return pte & 7;#endif
}
// deleted partApplication of the software “Coccinelle 1.0.8-00029-ga549b9f0” (OCaml 4.10.0)
elfring@Sonne:~/Projekte/Coccinelle/Probe> spatch --parse-c
paging_tmpl-excerpt1.h…
(ONCE) CPP-MACRO: found known macro = FNAME
…
parse error
= File "paging_tmpl-excerpt1.h", line 2, column 41, charpos = 57
around = 'unsigned',
…
BAD:!!!!! static inline int FNAME(is_present_gpte)(unsigned long pte) …
NB total files = 1; perfect = 0; pbs = 1; timeout = 0; =========> 0% nb good = 1, nb passed = 1 =========> 10.00% passed
nb good = 1, nb bad = 8 =========> 20.00% good or passed
Quoted 1 line
How would you like to improve the affected software areas?
This can be addressed by adding a macro definition to standard.h.
But once the change is done, I don't see any reason to bother with this.
julia
Re: [Cocci] [v3 05/10] mmap locking API: Improving the Coccinelle software
Quoted 4 lines
Quoted 4 lines
…
(ONCE) CPP-MACRO: found known macro = FNAME
…
parse error
…
Quoted 3 lines
Quoted 1 line
How would you like to improve the affected software areas?
This can be addressed by adding a macro definition to
standard.h.
A corresponding specification is used already.
https://github.com/coccinelle/coccinelle/blob/fdf0b68ddd0a518cc6ca64f063bc74ed54e29a7b/standard.h#L508
Quoted 1 line
But once the change is done, I don't see any reason to bother with this.
How will the support evolve for data processing around the application of similar macros?
Regards,
Markus
Re: [Cocci] [v3 05/10] mmap locking API: Improving the Coccinelle software
Quoted 9 lines · Markus Elfring
Quoted 4 lines
Quoted 4 lines
…
(ONCE) CPP-MACRO: found known macro = FNAME
…
parse error…
Quoted 3 lines
Quoted 1 line
How would you like to improve the affected software areas?
This can be addressed by adding a macro definition to
standard.h.
Quoted 8 lines
A corresponding specification is used already.
https://github.com/coccinelle/coccinelle/blob/fdf0b68ddd0a518cc6ca64f063bc74ed54e29a7b/standard.h#L508Quoted 1 line
But once the change is done, I don't see any reason to bother with this.
How will the support evolve for data processing around the application of similar macros?
Not at all.
julia
Re: [Cocci] [v3 05/10] mmap locking API: Improving the Coccinelle software
Quoted 4 lines
Quoted 2 lines
How will the support evolve for data processing around the application of similar macros?
Not at all.
Will such feedback trigger any collateral evolution?
Regards,
Markus
Peter Zijlstra
maintainerRe: [PATCH v3 06/10] mmap locking API: convert nested write lock sites
In reply to Michel Lespinasseinclude/linux/mmap_lock.h static inline void mmap_write_unlock(struct mm_struct *mm) · line 42
Quoted 13 lines · Michel Lespinasse
include/linux/mmap_lock.h +6
-0@@ -26,6 +31,12 @@ static inline void mmap_write_unlock(struct mm_struct *mm)up_write (&mm->mmap_sem); } +/* Pairs with mmap_write_lock_nested() */ +static inline void mmap_write_unlock_nested (struct mm_struct *mm) +{ +up_write (&mm->mmap_sem); +} +static inline void mmap_downgrade_write_lock (struct mm_struct *mm) {downgrade_write (&mm->mmap_sem);
Why does unlock_nested() make sense ?
Peter Zijlstra
maintainerRe: [PATCH v3 07/10] mmap locking API: add mmap_read_release() and mmap_read_unlock_non_owner()
In reply to Michel LespinasseQuoted 5 lines · Michel Lespinasse
Add a couple APIs to allow splitting
mmap_read_unlock()into two calls:
-mmap_read_release(), called by the task that had taken the mmap lock;
-mmap_read_unlock_non_owner(), called from a work queue.These apis are used by
kernel/bpf/stackmap.conly.
That code is an absolute abomination and should never have gotten merged.
That said; I would prefer a mmap_read_trylock_nonowner() over mmap_read_release() existing.
Quoted 25 lines
Signed-off-by Michel Lespinasse <[email protected]>--- include/linux/mmap_lock.h | 10 ++++++++++ kernel/bpf/stackmap.c | 9 ++++----- 2 files changed, 14 insertions(+), 5 deletions(-)include/linux/mmap_lock.h +10
-0@@ -62,4 +62,14 @@ static inline void mmap_read_unlock(struct mm_struct *mm) up_read(&mm->mmap_sem); } +static inline void mmap_read_release (struct mm_struct *mm,unsigned long ip) +{ +rwsem_release (&mm->mmap_sem.dep_map, ip); +} + +static inline void mmap_read_unlock_non_owner (struct mm_struct *mm) +{ +up_read_non_owner (&mm->mmap_sem); +} +#endif /* _LINUX_MMAP_LOCK_H */
Peter Zijlstra
maintainerRe: [PATCH v3 10/10] mmap locking API: rename mmap_sem to mmap_lock
In reply to Michel LespinasseQuoted 9 lines · Michel Lespinasse
Rename the
mmap_semfield tommap_lock. Any new uses of this lock should now go through the new mmap locking api. Themmap_lockis still implemented as a rwsem, though this could change in the future.include/linux/mm_types.h +0
-0
include/linux/mm_types.h struct mm_struct { · line 434
Quoted 5 lines
include/linux/mm_types.h +1
-1@@ -431,7 +431,7 @@ struct mm_struct {spinlock_t page_table_lock;/* Protects page tables and some * counters */ -struct rw_semaphore mmap_sem; +struct rw_semaphore mmap_lock;
It would be best if you change the type too.
Quoted 3 lines
include/linux/mm_types.h +0
-0struct list_head mmlist;/* List of maybe swapped mm's. These * are globally strung together off
Re: [PATCH v3 06/10] mmap locking API: convert nested write lock sites
In reply to Peter ZijlstraQuoted 7 lines · Peter Zijlstra
Quoted 4 lines · Michel Lespinasse
include/linux/mmap_lock.h +0
-0@@ -26,6 +31,12 @@ static inline void mmap_write_unlock(struct mm_struct *mm)up_write (&mm->mmap_sem); }
Quoted 11 lines
include/linux/mmap_lock.h static inline void mmap_write_unlock(struct mm_struct *mm) · line 42
Quoted 9 lines
include/linux/mmap_lock.h +6
-0+/* Pairs with mmap_write_lock_nested() */ +static inline void mmap_write_unlock_nested (struct mm_struct *mm) +{ +up_write (&mm->mmap_sem); +} +static inline void mmap_downgrade_write_lock (struct mm_struct *mm) {downgrade_write (&mm->mmap_sem);Why does
unlock_nested()make sense ?
I thought it would make things more explicit to match the nested lock with the corresponding unlock site; however this information is not used at the moment (i.e. the nested unlock is implemented identically to the regular unlock).
Having the matching sites explicitly identified may help when implementing lock instrumentation, or when changing the lock type (another patchset I am working on needs to pass an explicit lock range to the nested lock and unlock sites).
I'll admit this is not a super strong argument, and can be deferred to when an actual need shows up in the future.
Re: [PATCH v3 07/10] mmap locking API: add mmap_read_release() and mmap_read_unlock_non_owner()
In reply to Peter ZijlstraQuoted 9 lines · Peter Zijlstra
Quoted 5 lines · Michel Lespinasse
Add a couple APIs to allow splitting
mmap_read_unlock()into two calls:
-mmap_read_release(), called by the task that had taken the mmap lock;
-mmap_read_unlock_non_owner(), called from a work queue.These apis are used by
kernel/bpf/stackmap.conly.That code is an absolute abomination and should never have gotten merged.
I have to say, it's causing me some grief too :/
Quoted 2 lines
That said; I would prefer a
mmap_read_trylock_nonowner()overmmap_read_release()existing.
It only addresses part of the issue, but I suppose I could do that. Is this something I could append to the end of this series, or do I need to prepare a v4 for such changes ?
Re: [PATCH v3 10/10] mmap locking API: rename mmap_sem to mmap_lock
In reply to Peter ZijlstraQuoted 6 lines · Peter Zijlstra
Quoted 3 lines · Michel Lespinasse
Rename the
mmap_semfield tommap_lock. Any new uses of this lock should now go through the new mmap locking api. Themmap_lockis still implemented as a rwsem, though this could change in the future.
Quoted 12 lines
include/linux/mm_types.h struct mm_struct { · line 434
Quoted 10 lines
include/linux/mm_types.h +1
-1@@ -431,7 +431,7 @@ struct mm_struct {spinlock_t page_table_lock;/* Protects page tables and some * counters */ -struct rw_semaphore mmap_sem; +struct rw_semaphore mmap_lock;It would be best if you change the type too.
I suppose you mean wrapping the struct rw_semaphore within a new struct ? I did not do that in this patchset because there remains some calls to lockdep_assert_held() on that field, which imply that the field must have a .dep_map field that's not tucked away behind an additional struct.
I have another patchset that reimplements the mmap_lock as a different type (for range locking), with its own dep_map handling, but it's not ready for pushing to mainline yet...
Signature · 2 lines
Michel "Walken" Lespinasse A program is never fully debugged until the last user dies.
Peter Zijlstra
maintainerRe: [PATCH v3 06/10] mmap locking API: convert nested write lock sites
In reply to Michel LespinasseQuoted 25 lines · Michel Lespinasse
Quoted 7 lines · Peter Zijlstra
Quoted 4 lines · Michel Lespinasse
include/linux/mmap_lock.h +0
-0@@ -26,6 +31,12 @@ static inline void mmap_write_unlock(struct mm_struct *mm)up_write (&mm->mmap_sem); }Quoted 11 lines
include/linux/mmap_lock.h static inline void mmap_write_unlock(struct mm_struct *mm) · line 42
Quoted 9 lines
include/linux/mmap_lock.h +6
-0+/* Pairs with mmap_write_lock_nested() */ +static inline void mmap_write_unlock_nested (struct mm_struct *mm) +{ +up_write (&mm->mmap_sem); +} +static inline void mmap_downgrade_write_lock (struct mm_struct *mm) {downgrade_write (&mm->mmap_sem);Why does
unlock_nested()make sense ?I thought it would make things more explicit to match the nested lock with the corresponding unlock site; however this information is not used at the moment (i.e. the nested unlock is implemented identically to the regular unlock).
Quoted 7 lines
Having the matching sites explicitly identified may help when implementing lock instrumentation, or when changing the lock type (another patchset I am working on needs to pass an explicit lock range to the nested lock and unlock sites).
I'll admit this is not a super strong argument, and can be deferred to when an actual need shows up in the future.
The thing is, lock-acquisition order matters _a_lot_, lock-release order is irrelevant. ISTR there was a thread about this some 14 years ago, but please don't ask me to go find it :/
Re: [PATCH v3 05/10] mmap locking API: convert mmap_sem call sites missed by coccinelle
In reply to Michel LespinasseQuoted 4 lines · Michel Lespinasse
Convert the last few remaining
mmap_semrwsem calls to use the new mmap locking API. These were missed by coccinelle for some reason (I think coccinelle does not support some of the preprocessor constructs in these files ?)
Adding the wrappers for instrumentation makes sense to me. For patches 1-5, you can add
I'll wait for the next version to review the rest.