mm-make-per-vma-locks-available-universally.patch removed from -mm tree
The quilt patch titled
Subject: mm: make per-VMA locks available universally
has been removed from the -mm tree. Its filename was
mm-make-per-vma-locks-available-universally.patch
This patch was dropped because it was merged into the mm-stable branch of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
------------------------------------------------------
From: Dave Hansen <[email protected]>
Subject: mm: make per-VMA locks available universally
Date: Mon, 31 Aug 2026 13:30:52 -0700
Patch series "mm: Unconditional per-VMA locks and cleanups", v7.
tl;dr: Make per-VMA locks available in all configs. Simplify some of the per-VMA lock users now that they can rely on them being always available.
Binder and networking folks: Your code is the target of the cleanups. I'm cc'ing you now on v2 because there's emerging consensus on the mm side that the approach here is sane. I'm not quite sure how this pile would get merged, but ack/review tags would be appreciated if this looks good to you.
Longer version:
When working on some x86 shadow stack code, it was a real pain to avoid causing recursive locking problems with mmap_lock. One way to avoid those was to avoid mmap_lock and use per-VMA locks instead. They are great, but they are not available in all configs which makes them unusable in generic code, or if you want to completely avoid mmap_lock.
Make per-VMA locks available in all configs. Right now, they are only available on select architectures when SMP and MMU are enabled. But all of the primitives that per-VMA locks are built on (RCU, maple trees, refcounts) work just fine without SMP or MMU.
The only real downside is that making VMAs a wee bit bigger on !MMU and !SMP builds.
The upside is much cleaner code, lower complexity and less #ifdeffery.
Clean up a binder VMA locking site now that it can rely on per-VMA locks.
Building on top of universally-available per-VMA locks, introduce a new helper. Since the new API does not require callers to have a fallback to mmap_lock, it's much easier to use. Callers can potentially replace this very common kernel idiom:
mmap_read_lock(mm); vma = vma_lookup() // fiddle with vma mmap_read_unlock(mm);
with:
vma = vma_start_read_unlocked(mm, address); // fiddle with vma vma_end_read(vma);
Which avoids mmap_lock entirely in the fast path.
Use that new API for another binder site and one in the TCP code.
This patch (of 7):
The per-VMA locks have been around for several years. They've had some bugs worked out of them and have seen quite wide use. However, they are still only available when architectures explicitly enable them. Remove the conditional compilation around the per-VMA locks, making them available on all architectures and configs.
The approach up to now seemed to be to add ARCH_SUPPORTS_PER_VMA_LOCK when the architecture started using per-VMA locks in the fault handler. But, contrary to the naming, the Kconfig option does not really indicate whether the architecture supports per-VMA locks or not. It is more of a marker for whether the architecture is likely to benefit from per-VMA locks.
To me, the most important thing side-effect of universal availability is letting per-VMA locks be used in SMP=n configs. This lets us use per-VMA locking in all x86 code without fallbacks.
Overall, this just generally makes the kernel simpler. Just look at the diffstat. It also opens the door to users that want to use the per-VMA locks in common code. Doing *that* brings additional simplifications.
The downside of this is adding some fields to vm_area_struct and mm_struct. There are likely ways to optimize this, especially for things like SMP=n configs. For now, do the simplest thing: use the same implementation everywhere.
== Considerations for NOMMU config ==
NOMMU systems do not write-lock VMAs, therefore read-locking a VMA would always succeed unless VMA is detached. Therefore for NOMMU config we make vma_mark_attached() a NOOP, which keeps VMAs always in detached state. This causes VMA read-locking to always fail and the caller falls back to locking mmap_lock.
The following functions will have a different implementation in NOMMU config:
- vma_mark_attached(), vma_mark_detached() are made NOOPs, keeping VMAs always in a detached state and preventing assertions and refcount underflows;
- vma_start_write(), vma_start_write_killable() are made NOOPs to avoid warnings in __vma_start_write() due to VMAs being detached. These functions are not used in NOMMU code but __vma_start_write() is an exported function, therefore might be used by drivers.
- vma_assert_attached() is made NOOP because it's reachable from NOMMU code via split_vma()->vma_iter_store_new()->vma_iter_store_overwrite();
- vma_assert_write_locked() is asserting vma->vm_mm is write-locked, as was done before this change;
- vma_assert_locked() is asserting vma->vm_mm is locked, as was done before this change;
The following functions work for both MMU and NOMMU configs:
- vma_lock_init() performs the same initialization as for MMU config;
- mm_lock_seqcount_init(), mm_lock_seqcount_begin(), mm_lock_seqcount_end() are called from mmap_write_{lock|unlock} and update mm_lock_seq correctly.
- mmap_lock_speculate_try_begin(), mmap_lock_speculate_retry() work as is because mm_lock_seq is updated correctly;
- vma_start_read(), vma_start_read_locked() will always fail because VMAs are always detached;
- vma_end_read() will never be called because vma_start_read() never succeeds;
- vma_is_attached() always return false because VMAs are always detached;
- vma_assert_detached() will never trigger because VMAs are never attached;
- vma_start_read_locked() always return false because VMAs are always detached;
- lock_vma_under_rcu() will be safe as the attempted read lock will bail;
Changes in the following files are not affecting NOMMU config:
task_mmu.c - not compiled when CONFIG_MMU=n;pagewalk.c - not compiled when CONFIG_MMU=n;userfaultfd.c - not compiled when CONFIG_MMU=n (CONFIG_USERFAULTFD depends on CONFIG_MMU);
The following changes in the BPF code are made to keep NOMMU config working like before:
stack_map_lock_vma() - keeps mmap_lock in NOMMU config; bpf_iter_task_vma_new() - bails out in NOMMU config;
---
arch/arm/Kconfig | 1 arch/arm64/Kconfig | 1 arch/loongarch/Kconfig | 1 arch/powerpc/platforms/powernv/Kconfig | 1 arch/powerpc/platforms/pseries/Kconfig | 1 arch/riscv/Kconfig | 1 arch/s390/Kconfig | 1 arch/x86/Kconfig | 2 fs/proc/internal.h | 2 fs/proc/task_mmu.c | 93 ----------------------- include/linux/mm.h | 12 -- include/linux/mm_types.h | 8 - include/linux/mmap_lock.h | 75 ++++++------------ kernel/bpf/stackmap.c | 17 +--- kernel/bpf/task_iter.c | 2 kernel/fork.c | 2 mm/Kconfig | 12 -- mm/Kconfig.debug | 1 mm/debug.c | 4 mm/init-mm.c | 2 mm/memory.c | 2 mm/mmap_lock.c | 26 ------ mm/pagewalk.c | 2 mm/rmap.c | 2 mm/userfaultfd.c | 55 ------------- rust/kernel/mm.rs | 32 ++----- tools/testing/vma/include/dup.h | 5 - tools/testing/vma/vma_internal.h | 1 28 files changed, 48 insertions(+), 316 deletions(-)
arch/arm64/Kconfig renamed from arch/arm64/Kconfig~mm-make-per-vma-locks-available-universally +0 -1
@@ -81,7 +81,6 @@ config ARM64 select ARCH_HAS_PTE_PROTNONE select ARCH_SUPPORTS_NUMA_BALANCING select ARCH_SUPPORTS_PAGE_TABLE_CHECK - select ARCH_SUPPORTS_PER_VMA_LOCK select ARCH_SUPPORTS_HUGE_PFNMAP if TRANSPARENT_HUGEPAGE select ARCH_SUPPORTS_RT select ARCH_SUPPORTS_SCHED_SMT
arch/arm/Kconfig renamed from arch/arm/Kconfig~mm-make-per-vma-locks-available-universally +0 -1
@@ -42,7 +42,6 @@ config ARM select ARCH_SUPPORTS_ATOMIC_RMW select ARCH_SUPPORTS_CFI select ARCH_SUPPORTS_HUGETLBFS if ARM_LPAE - select ARCH_SUPPORTS_PER_VMA_LOCK select ARCH_SUPPORTS_RT select ARCH_USE_BUILTIN_BSWAP select ARCH_USE_CMPXCHG_LOCKREF
arch/loongarch/Kconfig renamed from arch/loongarch/Kconfig~mm-make-per-vma-locks-available-universally +0 -1
@@ -69,7 +69,6 @@ config LOONGARCH select ARCH_SUPPORTS_MSEAL_SYSTEM_MAPPINGS select ARCH_HAS_PTE_PROTNONE if 64BIT select ARCH_SUPPORTS_NUMA_BALANCING if NUMA - select ARCH_SUPPORTS_PER_VMA_LOCK select ARCH_SUPPORTS_RT select ARCH_SUPPORTS_SCHED_SMT if SMP select ARCH_SUPPORTS_SCHED_MC if SMP
arch/powerpc/platforms/powernv/Kconfig renamed from arch/powerpc/platforms/powernv/Kconfig~mm-make-per-vma-locks-available-universally +0 -1
@@ -17,7 +17,6 @@ config PPC_POWERNV select PPC_DOORBELL select MMU_NOTIFIER select FORCE_SMP - select ARCH_SUPPORTS_PER_VMA_LOCK select PPC_RADIX_BROADCAST_TLBIE if PPC_RADIX_MMU default y
arch/powerpc/platforms/pseries/Kconfig renamed from arch/powerpc/platforms/pseries/Kconfig~mm-make-per-vma-locks-available-universally +0 -1
@@ -23,7 +23,6 @@ config PPC_PSERIES select HOTPLUG_CPU select FORCE_SMP select SWIOTLB - select ARCH_SUPPORTS_PER_VMA_LOCK select PPC_RADIX_BROADCAST_TLBIE if PPC_RADIX_MMU default y
arch/riscv/Kconfig renamed from arch/riscv/Kconfig~mm-make-per-vma-locks-available-universally +0 -1
@@ -72,7 +72,6 @@ config RISCV select ARCH_SUPPORTS_LTO_CLANG_THIN select ARCH_SUPPORTS_MSEAL_SYSTEM_MAPPINGS if 64BIT && MMU select ARCH_SUPPORTS_PAGE_TABLE_CHECK if MMU - select ARCH_SUPPORTS_PER_VMA_LOCK if MMU select ARCH_HAS_PTE_PROTNONE if MMU select ARCH_SUPPORTS_RT select ARCH_SUPPORTS_SHADOW_CALL_STACK if HAVE_SHADOW_CALL_STACK
arch/s390/Kconfig renamed from arch/s390/Kconfig~mm-make-per-vma-locks-available-universally +0 -1
@@ -156,7 +156,6 @@ config S390 select ARCH_HAS_PTE_PROTNONE select ARCH_SUPPORTS_NUMA_BALANCING select ARCH_SUPPORTS_PAGE_TABLE_CHECK - select ARCH_SUPPORTS_PER_VMA_LOCK select ARCH_USES_CFI_GENERIC_LLVM_PASS if CC_IS_CLANG select ARCH_USE_BUILTIN_BSWAP select ARCH_USE_CMPXCHG_LOCKREF
arch/x86/Kconfig renamed from arch/x86/Kconfig~mm-make-per-vma-locks-available-universally +0 -2
@@ -27,7 +27,6 @@ config X86_64 select ARCH_HAS_GIGANTIC_PAGE select ARCH_SUPPORTS_MSEAL_SYSTEM_MAPPINGS select ARCH_SUPPORTS_INT128 if CC_HAS_INT128 - select ARCH_SUPPORTS_PER_VMA_LOCK select ARCH_SUPPORTS_HUGE_PFNMAP if TRANSPARENT_HUGEPAGE select HAVE_ARCH_SOFT_DIRTY select MODULES_USE_ELF_RELA
@@ -1848,7 +1847,6 @@ config X86_USER_SHADOW_STACK bool "X86 userspace shadow stack" depends on AS_WRUSS depends on X86_64 - depends on PER_VMA_LOCK select ARCH_USES_HIGH_VMA_FLAGS select ARCH_HAS_USER_SHADOW_STACK select X86_CET
fs/proc/internal.h renamed from fs/proc/internal.h~mm-make-per-vma-locks-available-universally +0 -2
@@ -385,10 +385,8 @@ struct mem_size_stats;struct proc_maps_locking_ctx {struct mm_struct *mm; -#ifdef CONFIG_PER_VMA_LOCK bool mmap_locked;struct vm_area_struct *locked_vma; -#endif };struct proc_maps_private {
fs/proc/task_mmu.c renamed from fs/proc/task_mmu.c~mm-make-per-vma-locks-available-universally +0 -93
141 lines not on this page · raw message
include/linux/mmap_lock.h renamed from include/linux/mmap_lock.h~mm-make-per-vma-locks-available-universally +25 -50
129 lines not on this page · raw message
include/linux/mm.h renamed from include/linux/mm.h~mm-make-per-vma-locks-available-universally +0 -12
@@ -928,7 +928,6 @@ static inline void vma_numab_state_free(* These must be here rather than mmap_lock.h as dependent on vm_fault type, * declared in this header. */ -#ifdef CONFIG_PER_VMA_LOCK static inline void release_fault_lock (struct vm_fault *vmf) {if (vmf->flags &FAULT_FLAG_VMA_LOCK )
@@ -944,17 +943,6 @@ static inline void assert_fault_locked(celse mmap_assert_locked (vmf->vma->vm_mm); } -#else -static inline void release_fault_lock (struct vm_fault *vmf) -{ -mmap_read_unlock (vmf->vma->vm_mm); -} - -static inline void assert_fault_locked (const struct vm_fault *vmf) -{ -mmap_assert_locked (vmf->vma->vm_mm); -} -#endif /* CONFIG_PER_VMA_LOCK */ static inline bool mm_flags_test (int flag,const struct mm_struct *mm) {
include/linux/mm_types.h renamed from include/linux/mm_types.h~mm-make-per-vma-locks-available-universally +2 -6
@@ -950,7 +950,6 @@ struct vm_area_struct {vma_flags_t flags; }; -#ifdef CONFIG_PER_VMA_LOCK /* * Can only be written (using WRITE_ONCE()) while holding both: * - mmap_lock (in write mode)
@@ -966,7 +965,7 @@ struct vm_area_struct {* slowpath. */ unsigned int vm_lock_seq; -#endif +/* * Low 32-bits of anonymous page offset. * See vma_start_anon_pgoff() comment for details.
@@ -1003,7 +1002,6 @@ struct vm_area_struct {#ifdef CONFIG_NUMA_BALANCING struct vma_numab_state *numab_state;/* NUMA Balancing state */ #endif -#ifdef CONFIG_PER_VMA_LOCK /* * Used to keep track of firstly, whether the VMA is attached, secondly, * if attached, how many read locks are taken, and thirdly, if the
@@ -1046,7 +1044,6 @@ struct vm_area_struct {#ifdef CONFIG_DEBUG_LOCK_ALLOC struct lockdep_map vmlock_dep_map;#endif -#endif #ifdef CONFIG_64BIT /* * High 32-bits of anonymous page offset.
@@ -1254,7 +1251,6 @@ struct mm_struct {* init_mm.mmlist, and are protected * by mmlist_lock */ -#ifdef CONFIG_PER_VMA_LOCK struct rcuwait vma_writer_wait;/* * This field has lock-like semantics, meaning it is sometimes
@@ -1274,7 +1270,7 @@ struct mm_struct {* mmap_lock. */ seqcount_t mm_lock_seq; -#endif +struct futex_mm_data futex;unsigned long hiwater_rss;/* High-watermark of RSS usage */
kernel/bpf/stackmap.c renamed from kernel/bpf/stackmap.c~mm-make-per-vma-locks-available-universally +6 -11
@@ -272,13 +272,10 @@ struct stack_map_vma_lock {/* * Acquire a stable read-side reference on the VMA covering @ip. * -* With CONFIG_PER_VMA_LOCK=y this returns a VMA with its per-VMA read -* lock held and mmap_lock dropped, so the caller may sleep. -* -* With CONFIG_PER_VMA_LOCK=n it returns a VMA with mmap_lock still -* held; the caller must snapshot any fields it needs and pin vm_file -* with get_file() before stack_map_unlock_vma() drops mmap_lock, as -* the VMA may be split, merged, or freed after that. +* On NOMMU configurations, returns with the mmap_lock held. If the MMU +* is enabled, the per-VMA lock will be held instead. The lock +* should be released with stack_map_unlock_vma() which will release the +* appropriate lock. Once the lock is released, the VMA may be freed. * * Returns NULL on failure, in which case no lock is held. */
@@ -288,7 +285,6 @@ stack_map_lock_vma(struct stack_map_vma_struct mm_struct *mm = lock->mm;struct vm_area_struct *vma; -/* noop under !CONFIG_PER_VMA_LOCK */ vma =lock_vma_under_rcu (mm, ip);if (vma) { lock->vma = vma;
@@ -308,21 +304,20 @@ stack_map_lock_vma(struct stack_map_vma_return NULL ; } -#ifdef CONFIG_PER_VMA_LOCK +#ifdef CONFIG_MMU if (!vma_start_read_locked (vma)) {mmap_read_unlock (mm);return NULL ; }mmap_read_unlock (mm);#endif - lock->vma = vma;return vma; }static void stack_map_unlock_vma (struct stack_map_vma_lock *lock) { -#ifdef CONFIG_PER_VMA_LOCK +#ifdef CONFIG_MMU vma_end_read (lock->vma);#else mmap_read_unlock (lock->mm);
kernel/bpf/task_iter.c renamed from kernel/bpf/task_iter.c~mm-make-per-vma-locks-available-universally +1 -1
@@ -869,7 +869,7 @@ __bpf_kfunc int bpf_iter_task_vma_new(stBUILD_BUG_ON (sizeof (struct bpf_iter_task_vma_kern ) !=sizeof (struct bpf_iter_task_vma ));BUILD_BUG_ON (__alignof__(struct bpf_iter_task_vma_kern ) != __alignof__(struct bpf_iter_task_vma )); -if (!IS_ENABLED (CONFIG_PER_VMA_LOCK )) { +if (!IS_ENABLED (CONFIG_MMU )) { kit->data =NULL ;return -EOPNOTSUPP ; }
kernel/fork.c renamed from kernel/fork.c~mm-make-per-vma-locks-available-universally +0 -2
@@ -1083,9 +1083,7 @@ static void mmap_init_lock(struct mm_str {init_rwsem (&mm->mmap_lock);mm_lock_seqcount_init (mm); -#ifdef CONFIG_PER_VMA_LOCK rcuwait_init (&mm->vma_writer_wait); -#endif }static struct mm_struct *mm_init (struct mm_struct *mm,struct task_struct *p)
mm/debug.c renamed from mm/debug.c~mm-make-per-vma-locks-available-universally +0 -4
@@ -157,17 +157,13 @@ void dump_vma(const struct vm_area_strucpr_emerg ("vma %px start %px end %px mm %px\n" "prot %lx anon_vma %px vm_ops %px\n" "pgoff %lx file %px private_data %px\n" -#ifdef CONFIG_PER_VMA_LOCK"refcnt %x\n" -#endif"flags: %#lx(%pGv)\n" , vma, (void *)vma->vm_start, (void *)vma->vm_end, vma->vm_mm, (unsigned long )pgprot_val (vma->vm_page_prot), vma->anon_vma, vma->vm_ops,vma_start_pgoff (vma), vma->vm_file, vma->vm_private_data, -#ifdef CONFIG_PER_VMA_LOCKrefcount_read (&vma->vm_refcnt), -#endif vma->vm_flags, &vma->vm_flags); }EXPORT_SYMBOL (dump_vma);
mm/init-mm.c renamed from mm/init-mm.c~mm-make-per-vma-locks-available-universally +0 -2
@@ -39,10 +39,8 @@ struct mm_struct init_mm = { .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), -#ifdef CONFIG_PER_VMA_LOCK .vma_writer_wait = __RCUWAIT_INITIALIZER(init_mm.vma_writer_wait), .mm_lock_seq = SEQCNT_ZERO(init_mm.mm_lock_seq), -#endif #ifdef CONFIG_SCHED_MM_CID .mm_cid.lock = __RAW_SPIN_LOCK_UNLOCKED(init_mm.mm_cid.lock),#endif
mm/Kconfig renamed from mm/Kconfig~mm-make-per-vma-locks-available-universally +0 -12
@@ -1425,18 +1425,6 @@ config LRU_GEN_WALKS_MMU depends on LRU_GEN && ARCH_HAS_HW_PTE_YOUNG # } -config ARCH_SUPPORTS_PER_VMA_LOCK - def_bool n - -config PER_VMA_LOCK - def_bool y - depends on ARCH_SUPPORTS_PER_VMA_LOCK && MMU && SMP - help - Allow per-vma locking during page fault handling. - - This feature allows locking each virtual memory area separately when - handling page faults instead of taking mmap_lock. - config LOCK_MM_AND_FIND_VMA bool depends on !STACK_GROWSUP
mm/Kconfig.debug renamed from mm/Kconfig.debug~mm-make-per-vma-locks-available-universally +0 -1
@@ -310,7 +310,6 @@ config DEBUG_KMEMLEAK_VERBOSE config PER_VMA_LOCK_STATS bool "Statistics for per-vma locks" - depends on PER_VMA_LOCK help Say Y here to enable success, retry and failure counters of page faults handled under protection of per-vma locks. When enabled, the
mm/memory.c renamed from mm/memory.c~mm-make-per-vma-locks-available-universally +0 -2
@@ -6799,7 +6799,6 @@ static vm_fault_t sanitize_fault_flags(s !vma_is_cow_mapping(vma)))return VM_FAULT_SIGSEGV ; } -#ifdef CONFIG_PER_VMA_LOCK /* * Per-VMA locks can't be used with FAULT_FLAG_RETRY_NOWAIT because of * the assumption that lock is dropped on VM_FAULT_RETRY.
@@ -6808,7 +6807,6 @@ static vm_fault_t sanitize_fault_flags(s (FAULT_FLAG_VMA_LOCK | FAULT_FLAG_RETRY_NOWAIT)) == (FAULT_FLAG_VMA_LOCK | FAULT_FLAG_RETRY_NOWAIT)))return VM_FAULT_SIGSEGV ; -#endif return 0 ; }
mm/mmap_lock.c renamed from mm/mmap_lock.c~mm-make-per-vma-locks-available-universally +2 -24
@@ -43,9 +43,6 @@ void __mmap_lock_do_trace_released(strucEXPORT_SYMBOL (__mmap_lock_do_trace_released);#endif /* CONFIG_TRACING */ -#ifdef CONFIG_MMU -#ifdef CONFIG_PER_VMA_LOCK -/* State shared across __vma_[start, end]_exclude_readers. */ struct vma_exclude_readers_state {/* Input parameters. */
@@ -299,6 +296,8 @@ struct vm_area_struct *lock_vma_under_rcMA_STATE (mas, &mm->mm_mt, address, address);struct vm_area_struct *vma; +if (!IS_ENABLED (CONFIG_MMU )) +return NULL ; retry:rcu_read_lock (); vma =mas_walk (&mas);
@@ -431,7 +430,6 @@ fallback:return vma; } -#endif /* CONFIG_PER_VMA_LOCK */ #ifdef CONFIG_LOCK_MM_AND_FIND_VMA #include <linux/extable.h>
@@ -548,23 +546,3 @@ fail: return NULL; }#endif /* CONFIG_LOCK_MM_AND_FIND_VMA */ - -#else /* CONFIG_MMU */ - -/* -* At least xtensa ends up having protection faults even with no -* MMU.. No stack expansion, at least. -*/ -struct vm_area_struct *lock_mm_and_find_vma (struct mm_struct *mm, -unsigned long addr,struct pt_regs *regs) -{ -struct vm_area_struct *vma; - -mmap_read_lock (mm); - vma =vma_lookup (mm, addr); -if (!vma) -mmap_read_unlock (mm); -return vma; -} - -#endif /* CONFIG_MMU */
mm/pagewalk.c renamed from mm/pagewalk.c~mm-make-per-vma-locks-available-universally +0 -2
@@ -444,7 +444,6 @@ static inline void process_mm_walk_lock(static inline void process_vma_walk_lock (struct vm_area_struct *vma,enum page_walk_lock walk_lock) { -#ifdef CONFIG_PER_VMA_LOCK switch (walk_lock) {case PGWALK_WRLOCK :vma_start_write (vma);
@@ -459,7 +458,6 @@ static inline void process_vma_walk_lock/* PGWALK_RDLOCK is handled by process_mm_walk_lock */ break ; } -#endif }/*
mm/rmap.c renamed from mm/rmap.c~mm-make-per-vma-locks-available-universally +0 -2
@@ -264,11 +264,9 @@ static void check_anon_vma_clone(struct/* For the anon_vma to be compatible, it can only be singular. */ VM_WARN_ON_ONCE (operation ==VMA_OP_MERGE_UNFAULTED && !list_is_singular (&src->anon_vma_chain)); -#ifdef CONFIG_PER_VMA_LOCK /* Only merging an unfaulted VMA leaves the destination attached. */ VM_WARN_ON_ONCE (operation !=VMA_OP_MERGE_UNFAULTED &&vma_is_attached (dst)); -#endif } static void maybe_reuse_anon_vma(struct vm_area_struct *dst,
mm/userfaultfd.c renamed from mm/userfaultfd.c~mm-make-per-vma-locks-available-universally +0 -55
79 lines not on this page · raw message
rust/kernel/mm.rs renamed from rust/kernel/mm.rs~mm-make-per-vma-locks-available-universally +11 -21
@@ -170,30 +170,20 @@ impl MmWithUser {/// /// This is an optimistic trylock operation, so it may fail if there is contention. In that /// case, you should fall back to taking the mmap read lock. -/// -/// When per-vma locks are disabled, this always returns `None`. #[inline] pub fn lock_vma_under_rcu (&self, vma_addr:usize ) ->Option <VmaReadGuard <'_>> { -#[cfg( CONFIG_PER_VMA_LOCK )] - { -// SAFETY: Calling `bindings::lock_vma_under_rcu` is always okay given an mm where -// `mm_users` is non-zero. -let vma =unsafe { bindings::lock_vma_under_rcu (self.as_raw (), vma_addr) }; -if !vma.is_null () { -return Some (VmaReadGuard { -// SAFETY: If `lock_vma_under_rcu` returns a non-null ptr, then it points at a -// valid vma. The vma is stable for as long as the vma read lock is held. - vma:unsafe {VmaRef ::from_raw (vma) }, - _nts:NotThreadSafe , - }); - } +// SAFETY: Calling `bindings::lock_vma_under_rcu` is always okay given an mm where +// `mm_users` is non-zero. +let vma =unsafe { bindings::lock_vma_under_rcu (self.as_raw (), vma_addr) }; +if vma.is_null () { +return None ; } - -// Silence warnings about unused variables. -#[cfg(not( CONFIG_PER_VMA_LOCK ))] -let _ = vma_addr; - -None +Some (VmaReadGuard { +// SAFETY: If `lock_vma_under_rcu` returns a non-null ptr, then it points at a +// valid vma. The vma is stable for as long as the vma read lock is held. + vma:unsafe {VmaRef ::from_raw (vma) }, + _nts:NotThreadSafe , + }) }/// Lock the mmap read lock.
tools/testing/vma/include/dup.h renamed from tools/testing/vma/include/dup.h~mm-make-per-vma-locks-available-universally +1 -4
@@ -560,7 +560,6 @@ struct vm_area_struct {vma_flags_t flags; }; -#ifdef CONFIG_PER_VMA_LOCK /* * Can only be written (using WRITE_ONCE()) while holding both: * - mmap_lock (in write mode)
@@ -576,7 +575,7 @@ struct vm_area_struct {* slowpath. */ unsigned int vm_lock_seq; -#endif +unsigned int __vm_anon_pgoff_lo;/*
@@ -610,10 +609,8 @@ struct vm_area_struct {#ifdef CONFIG_NUMA_BALANCING struct vma_numab_state *numab_state;/* NUMA Balancing state */ #endif -#ifdef CONFIG_PER_VMA_LOCK /* Unstable RCU readers are allowed to read this. */ refcount_t vm_refcnt; -#endif #ifdef CONFIG_64BIT unsigned int __vm_anon_pgoff_hi;#endif
tools/testing/vma/vma_internal.h renamed from tools/testing/vma/vma_internal.h~mm-make-per-vma-locks-available-universally +0 -1
@@ -15,7 +15,6 @@#include <stdlib.h> #define CONFIG_MMU 1 -#define CONFIG_PER_VMA_LOCK 1#ifdef __CONCAT#undef __CONCAT
_
Patches currently in -mm which might be from [email protected] are