From nobody Wed Sep 30 14:43:32 2026 Received: from mail-pj1-f70.google.com (mail-pj1-f70.google.com [209.85.216.70]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8506B48F82F for ; Thu, 6 Aug 2026 20:05:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.70 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786046770; cv=none; b=dDoh7tgGyGzxY/iVs1a7SveVZ3JI8xm65ZHCrNyWT0zkAWSn0wZPMp4Kgy9WIdnw1ggJU4UxmKa5ctXfBzRkoMOQ/vP84yz/r/DDMD3kmSqhYpYwkyQvk2vRYH3k5DsnL13XBPwcgmKzZfZtyKroiPKmgWa3zpLM2dD/uM/xIKI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786046770; c=relaxed/simple; bh=Wg7U+6GhAdCrxpo7T6ipB/e3CQzq3JQT/dg7pQI3On8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=sCWAqrLCqLVWrNwKlxiJM7WwqeqK1OBLPTPpHyyeMOEEMqp4+3vP4mlPxOfdeYWpO+9PYcI1KWDpb3kuFznsViXoUif8eZqcqdbPTAu4WSdQZnBjyPClydeN1U7vdzco35JUZUpW+4UiiTG3mQTHeyzGRQ0SWGSr89YABIIw7Kw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--surenb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=DNvqfKdv; arc=none smtp.client-ip=209.85.216.70 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--surenb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="DNvqfKdv" Received: by mail-pj1-f70.google.com with SMTP id 98e67ed59e1d1-38fcaa5f82cso2489410a91.3 for ; Thu, 06 Aug 2026 13:05:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1786046754; x=1786651554; darn=vger.kernel.org; h=content-transfer-encoding:content-type:cc:to:from:subject :message-id:references:mime-version:in-reply-to:date:from:to:cc :subject:date:message-id:reply-to:content-type; bh=/Y5QFRn8flJrzgCLSCve4S6nH1Sggk7xxzVmeuM+qw8=; b=DNvqfKdvc23obKR6lgudVxa8MJJZmpsjjvUgkfog36GoEc1eaNy1wtblsbm2EB/57l 8rzK9GJLR+igzCtWQplTBpKAo8gTGRXQuK8ZRFPyOsL9OUFbi7wv3qxRpm8DLCI1qr5a 789qxzhfYtL+1C1fyKhRVEzCEwQHkeaqABM9o3+GPZlaVdpH/2WrMNHxxEEjmzy2J6Bd bOKKebITnTq59g/XgO4Gk5j+H8nVJfC1HCVcKlybIu5eNSLZXD+YBRXB0QRzS8dUFJeg Y1OiYI0+6dF/0YB78fsnwrWTmPsywCHSwKqQqANNnN0Y3AnqDA6usm6sLUmKE45Vu85z bAUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786046754; x=1786651554; h=content-transfer-encoding:content-type:cc:to:from:subject :message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=/Y5QFRn8flJrzgCLSCve4S6nH1Sggk7xxzVmeuM+qw8=; b=WFndR0U5HIt9RaXAPmAsZTZ+aUdU6p/XsTXZce04aOr/iTliha2fCVYfjgTHUhuJ0T XUEG0lwfzpijZhmNNIu1uXqhhF4qJZtkSNBj06Wgy0shO1UWAnB6N3AiFa3kUb6KJ5mh oEMTbq3D86WtPzdx4G+XPeTIf0oK4XpbtGwT237RBxDu3nxx9HueaYh6E1cHEq5y56Ha tGmKst+i+G+CN0F6xyDFfembkrQs6BWPd/KzD7wrE7AZMd/IuYYbmA5nFKG1olHFnRAI n7qfZEdtKYODJnaEFReTSJT87ORFLUuikjzzEZ1jmG0YK7+JT1M0sKsVsstNGb5Ey6gI sdwQ== X-Forwarded-Encrypted: i=1; AHgh+RprudjEi5hvAKWoMIrHHmOUO17p3huIQ+/yzrqY+NeHituuuxiw0IgOUhCKHZk5MEwf0+/cC6iAiD5k4kk=@vger.kernel.org X-Gm-Message-State: AOJu0Yw7dsjvR3+E+7lkBwhZGYomFWAoYUqysKDdk/58cBlwhoVmrIU4 uYRgOTupuGz6CluuVie4eMGk0DwgKvVNOjIPp0z9UM3aTwd0HqTQ69oSpkAwXI4sU2/4cSE55G0 10Jpkxg== X-Received: from dli20-n1.prod.google.com ([2002:a05:7022:294:10b0:13b:97f1:acba]) (user=surenb job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:5683:b0:381:26f:8f05 with SMTP id 98e67ed59e1d1-3903c5380f7mr17303261a91.3.1786046753666; Thu, 06 Aug 2026 13:05:53 -0700 (PDT) Date: Thu, 6 Aug 2026 13:05:44 -0700 In-Reply-To: <20260806200548.3124802-1-surenb@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260806200548.3124802-1-surenb@google.com> X-Mailer: git-send-email 2.55.0.654.g21b8a5bc05-goog Message-ID: <20260806200548.3124802-2-surenb@google.com> Subject: [PATCH v4 1/5] mm: Make per-VMA locks available universally From: Suren Baghdasaryan To: akpm@linux-foundation.org Cc: dave.hansen@linux.intel.com, Liam.Howlett@oracle.com, ljs@kernel.org, david@kernel.org, willy@infradead.org, shakeel.butt@linux.dev, vbabka@kernel.org, jannh@google.com, aliceryhl@google.com, arve@android.com, cmllamas@google.com, christian@brauner.io, tkjos@android.com, dsahern@kernel.org, davem@davemloft.net, gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, netdev@vger.kernel.org, surenb@google.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Dave Hansen 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=3Dn 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=3Dn configs. For now, do the simplest thing: use the same implementation everywhere. =3D=3D Considerations for NOMMU config =3D=3D 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; 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; Changes in the following files are not affecting NOMMU config: task_mmu.c - not compiled when CONFIG_MMU=3Dn; pagewalk.c - not compiled when CONFIG_MMU=3Dn; userfaultfd.c - not compiled when CONFIG_MMU=3Dn (CONFIG_USERFAULTFD depends on CONFIG_MMU); The following changes 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; Signed-off-by: Dave Hansen Signed-off-by: Suren Baghdasaryan Cc: Suren Baghdasaryan Cc: Andrew Morton Cc: "Liam R. Howlett" Cc: Lorenzo Stoakes Cc: Vlastimil Babka Cc: Shakeel Butt Cc: linux-mm@kvack.org Cc: Greg Kroah-Hartman Cc: Arve Hj=C3=B8nnev=C3=A5g Cc: Todd Kjos Cc: Christian Brauner Cc: Carlos Llamas Cc: Alice Ryhl Cc: "David S. Miller" Cc: David Ahern Cc: netdev@vger.kernel.org Acked-by: Vlastimil Babka (SUSE) --- 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 | 70 ++++++------------- kernel/bpf/stackmap.c | 15 ++--- 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 | 24 ------- 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, 39 insertions(+), 316 deletions(-) diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index 9187240a02db..f815209167cd 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -41,7 +41,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 diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 11a9c534b7b4..21eb64b24a2c 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -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 diff --git a/arch/loongarch/Kconfig b/arch/loongarch/Kconfig index e20acbe5fe7b..7741e39eca2b 100644 --- a/arch/loongarch/Kconfig +++ b/arch/loongarch/Kconfig @@ -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 diff --git a/arch/powerpc/platforms/powernv/Kconfig b/arch/powerpc/platform= s/powernv/Kconfig index b5ad7c173ef0..dd8f6060fb7a 100644 --- a/arch/powerpc/platforms/powernv/Kconfig +++ b/arch/powerpc/platforms/powernv/Kconfig @@ -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 =20 diff --git a/arch/powerpc/platforms/pseries/Kconfig b/arch/powerpc/platform= s/pseries/Kconfig index 74910ce3a541..7d125e288f6e 100644 --- a/arch/powerpc/platforms/pseries/Kconfig +++ b/arch/powerpc/platforms/pseries/Kconfig @@ -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 =20 diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index 7b9c373d82fa..faa85a031fe5 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -70,7 +70,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 diff --git a/arch/s390/Kconfig b/arch/s390/Kconfig index ab8fccc2cc4e..d1274bca8c39 100644 --- a/arch/s390/Kconfig +++ b/arch/s390/Kconfig @@ -151,7 +151,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_USE_BUILTIN_BSWAP select ARCH_USE_CMPXCHG_LOCKREF select ARCH_USE_SYM_ANNOTATIONS diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index fb298e219179..79479d29576f 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -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 @@ -1846,7 +1845,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 diff --git a/fs/proc/internal.h b/fs/proc/internal.h index b232e1098117..6713757da099 100644 --- a/fs/proc/internal.h +++ b/fs/proc/internal.h @@ -385,10 +385,8 @@ struct mem_size_stats; =20 struct proc_maps_locking_ctx { struct mm_struct *mm; -#ifdef CONFIG_PER_VMA_LOCK bool mmap_locked; struct vm_area_struct *locked_vma; -#endif }; =20 struct proc_maps_private { diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index 817e3e0f9194..096bf0b0b9e0 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -130,8 +130,6 @@ static void release_task_mempolicy(struct proc_maps_pri= vate *priv) } #endif =20 -#ifdef CONFIG_PER_VMA_LOCK - static inline int lock_ctx_mm(struct proc_maps_locking_ctx *lock_ctx) { int ret =3D mmap_read_lock_killable(lock_ctx->mm); @@ -233,46 +231,6 @@ static inline void reacquire_rcu(struct proc_maps_priv= ate *priv) vma_iter_set(&priv->iter, priv->lock_ctx.locked_vma->vm_end); } =20 -#else /* CONFIG_PER_VMA_LOCK */ - -static inline int lock_ctx_mm(struct proc_maps_locking_ctx *lock_ctx) -{ - return mmap_read_lock_killable(lock_ctx->mm); -} - -static inline void unlock_ctx_mm(struct proc_maps_locking_ctx *lock_ctx) -{ - mmap_read_unlock(lock_ctx->mm); -} - -static inline bool lock_vma_range(struct seq_file *m, - struct proc_maps_locking_ctx *lock_ctx) -{ - return lock_ctx_mm(lock_ctx) =3D=3D 0; -} - -static inline void unlock_vma_range(struct proc_maps_locking_ctx *lock_ctx) -{ - unlock_ctx_mm(lock_ctx); -} - -static struct vm_area_struct *get_next_vma(struct proc_maps_private *priv, - loff_t last_pos) -{ - return vma_next(&priv->iter); -} - -static inline bool fallback_to_mmap_lock(struct proc_maps_private *priv, - loff_t pos) -{ - return false; -} - -static inline void drop_rcu(struct proc_maps_private *priv) {} -static inline void reacquire_rcu(struct proc_maps_private *priv) {} - -#endif /* CONFIG_PER_VMA_LOCK */ - static struct vm_area_struct *proc_get_vma(struct seq_file *m, loff_t *ppo= s) { struct proc_maps_private *priv =3D m->private; @@ -560,8 +518,6 @@ static int pid_maps_open(struct inode *inode, struct fi= le *file) PROCMAP_QUERY_VMA_FLAGS \ ) =20 -#ifdef CONFIG_PER_VMA_LOCK - static int query_vma_setup(struct proc_maps_locking_ctx *lock_ctx) { reset_lock_ctx(lock_ctx); @@ -612,26 +568,6 @@ static struct vm_area_struct *query_vma_find_by_addr(s= truct proc_maps_locking_ct return vma; } =20 -#else /* CONFIG_PER_VMA_LOCK */ - -static int query_vma_setup(struct proc_maps_locking_ctx *lock_ctx) -{ - return mmap_read_lock_killable(lock_ctx->mm); -} - -static void query_vma_teardown(struct proc_maps_locking_ctx *lock_ctx) -{ - mmap_read_unlock(lock_ctx->mm); -} - -static struct vm_area_struct *query_vma_find_by_addr(struct proc_maps_lock= ing_ctx *lock_ctx, - unsigned long addr) -{ - return find_vma(lock_ctx->mm, addr); -} - -#endif /* CONFIG_PER_VMA_LOCK */ - static struct vm_area_struct *query_matching_vma(struct proc_maps_locking_= ctx *lock_ctx, unsigned long addr, u32 flags) { @@ -1314,8 +1250,6 @@ static const struct mm_walk_ops smaps_shmem_walk_ops = =3D { .walk_lock =3D PGWALK_RDLOCK, }; =20 -#ifdef CONFIG_PER_VMA_LOCK - static const struct mm_walk_ops smaps_walk_vma_lock_ops =3D { .pmd_entry =3D smaps_pte_range, .hugetlb_entry =3D smaps_hugetlb_range, @@ -1345,22 +1279,6 @@ get_smaps_shmem_walk_ops(struct proc_maps_private *p= riv) return &smaps_shmem_walk_vma_lock_ops; } =20 -#else /* CONFIG_PER_VMA_LOCK */ - -static inline const struct mm_walk_ops * -get_smaps_walk_ops(struct proc_maps_private *priv) -{ - return &smaps_walk_ops; -} - -static inline const struct mm_walk_ops * -get_smaps_shmem_walk_ops(struct proc_maps_private *priv) -{ - return &smaps_shmem_walk_ops; -} - -#endif /* CONFIG_PER_VMA_LOCK */ - /* * Gather mem stats from @vma with the indicated beginning * address @start, and keep them in @mss. @@ -3497,7 +3415,6 @@ static const struct mm_walk_ops show_numa_ops =3D { .walk_lock =3D PGWALK_RDLOCK, }; =20 -#ifdef CONFIG_PER_VMA_LOCK static const struct mm_walk_ops show_numa_vma_lock_ops =3D { .hugetlb_entry =3D gather_hugetlb_stats, .pmd_entry =3D gather_pte_stats, @@ -3512,16 +3429,6 @@ get_show_numa_ops(struct proc_maps_private *priv) return &show_numa_vma_lock_ops; } =20 -#else /* CONFIG_PER_VMA_LOCK */ - -static inline const struct mm_walk_ops * -get_show_numa_ops(struct proc_maps_private *priv) -{ - return &show_numa_ops; -} - -#endif /* CONFIG_PER_VMA_LOCK */ - /* * Display pages allocated per node and memory policy via /proc. */ diff --git a/include/linux/mm.h b/include/linux/mm.h index 7fabe6c66b4b..d9850f846242 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -931,7 +931,6 @@ static inline void vma_numab_state_free(struct vm_area_= struct *vma) {} * These must be here rather than mmap_lock.h as dependent on vm_fault typ= e, * 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) @@ -947,17 +946,6 @@ static inline void assert_fault_locked(const struct vm= _fault *vmf) else 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 */ =20 static inline bool mm_flags_test(int flag, const struct mm_struct *mm) { diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h index b5d4cd3b067b..d8e246fd09d3 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -950,7 +950,6 @@ struct vm_area_struct { vma_flags_t flags; }; =20 -#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 virtual page offset. * See vma_start_virt_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 virtual 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; =20 unsigned long hiwater_rss; /* High-watermark of RSS usage */ diff --git a/include/linux/mmap_lock.h b/include/linux/mmap_lock.h index 87f77e3da77f..7b2bbb09a952 100644 --- a/include/linux/mmap_lock.h +++ b/include/linux/mmap_lock.h @@ -76,8 +76,6 @@ static inline void mmap_assert_write_locked(const struct = mm_struct *mm) rwsem_assert_held_write(&mm->mmap_lock); } =20 -#ifdef CONFIG_PER_VMA_LOCK - #ifdef CONFIG_LOCKDEP #define __vma_lockdep_map(vma) (&vma->vmlock_dep_map) #else @@ -297,6 +295,9 @@ int __vma_start_write(struct vm_area_struct *vma, int s= tate); */ static inline void vma_start_write(struct vm_area_struct *vma) { + if (!IS_ENABLED(CONFIG_MMU)) + return; + if (__is_vma_write_locked(vma)) return; =20 @@ -319,6 +320,9 @@ static inline void vma_start_write(struct vm_area_struc= t *vma) static inline __must_check int vma_start_write_killable(struct vm_area_struct *vma) { + if (!IS_ENABLED(CONFIG_MMU)) + return 0; + if (__is_vma_write_locked(vma)) return 0; =20 @@ -331,6 +335,11 @@ int vma_start_write_killable(struct vm_area_struct *vm= a) */ static inline void vma_assert_write_locked(struct vm_area_struct *vma) { + if (!IS_ENABLED(CONFIG_MMU)) { + mmap_assert_write_locked(vma->vm_mm); + return; + } + VM_WARN_ON_ONCE_VMA(!__is_vma_write_locked(vma), vma); } =20 @@ -432,6 +441,9 @@ static inline bool vma_is_attached(struct vm_area_struc= t *vma) */ static inline void vma_assert_attached(struct vm_area_struct *vma) { + if (!IS_ENABLED(CONFIG_MMU)) + return; + WARN_ON_ONCE(!vma_is_attached(vma)); } =20 @@ -442,6 +454,9 @@ static inline void vma_assert_detached(struct vm_area_s= truct *vma) =20 static inline void vma_mark_attached(struct vm_area_struct *vma) { + if (!IS_ENABLED(CONFIG_MMU)) + return; + vma_assert_write_locked(vma); vma_assert_detached(vma); refcount_set_release(&vma->vm_refcnt, 1); @@ -451,6 +466,9 @@ void __vma_exclude_readers_for_detach(struct vm_area_st= ruct *vma); =20 static inline void vma_mark_detached(struct vm_area_struct *vma) { + if (!IS_ENABLED(CONFIG_MMU)) + return; + vma_assert_write_locked(vma); vma_assert_attached(vma); =20 @@ -484,54 +502,6 @@ struct vm_area_struct *lock_next_vma(struct mm_struct = *mm, struct vma_iterator *iter, unsigned long address); =20 -#else /* CONFIG_PER_VMA_LOCK */ - -static inline void mm_lock_seqcount_init(struct mm_struct *mm) {} -static inline void mm_lock_seqcount_begin(struct mm_struct *mm) {} -static inline void mm_lock_seqcount_end(struct mm_struct *mm) {} - -static inline bool mmap_lock_speculate_try_begin(struct mm_struct *mm, uns= igned int *seq) -{ - return false; -} - -static inline bool mmap_lock_speculate_retry(struct mm_struct *mm, unsigne= d int seq) -{ - return true; -} -static inline void vma_lock_init(struct vm_area_struct *vma, bool reset_re= fcnt) {} -static inline void vma_end_read(struct vm_area_struct *vma) {} -static inline void vma_start_write(struct vm_area_struct *vma) {} -static inline __must_check -int vma_start_write_killable(struct vm_area_struct *vma) { return 0; } -static inline void vma_assert_write_locked(struct vm_area_struct *vma) - { mmap_assert_write_locked(vma->vm_mm); } -static inline bool vma_is_attached(struct vm_area_struct *vma) - { return true; } -static inline void vma_assert_attached(struct vm_area_struct *vma) {} -static inline void vma_assert_detached(struct vm_area_struct *vma) {} -static inline void vma_mark_attached(struct vm_area_struct *vma) {} -static inline void vma_mark_detached(struct vm_area_struct *vma) {} - -static inline struct vm_area_struct *lock_vma_under_rcu(struct mm_struct *= mm, - unsigned long address) -{ - return NULL; -} - -static inline void vma_assert_locked(struct vm_area_struct *vma) -{ - mmap_assert_locked(vma->vm_mm); -} - -static inline void vma_assert_stabilised(struct vm_area_struct *vma) -{ - /* If no VMA locks, then either mmap lock suffices to stabilise. */ - mmap_assert_locked(vma->vm_mm); -} - -#endif /* CONFIG_PER_VMA_LOCK */ - static inline void vma_assert_can_modify(struct vm_area_struct *vma) { if (vma_is_attached(vma)) diff --git a/kernel/bpf/stackmap.c b/kernel/bpf/stackmap.c index 41fe87d7302f..b15ee4b9ac4e 100644 --- a/kernel/bpf/stackmap.c +++ b/kernel/bpf/stackmap.c @@ -272,13 +272,8 @@ struct stack_map_vma_lock { /* * Acquire a stable read-side reference on the VMA covering @ip. * - * With CONFIG_PER_VMA_LOCK=3Dy 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=3Dn 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. + * This returns a VMA with its per-VMA read lock held and mmap_lock + * dropped, so the caller may sleep. * * Returns NULL on failure, in which case no lock is held. */ @@ -288,7 +283,6 @@ stack_map_lock_vma(struct stack_map_vma_lock *lock, uns= igned long ip) struct mm_struct *mm =3D lock->mm; struct vm_area_struct *vma; =20 - /* noop under !CONFIG_PER_VMA_LOCK */ vma =3D lock_vma_under_rcu(mm, ip); if (vma) { lock->vma =3D vma; @@ -308,21 +302,20 @@ stack_map_lock_vma(struct stack_map_vma_lock *lock, u= nsigned long ip) return NULL; } =20 -#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 =3D vma; return vma; } =20 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); diff --git a/kernel/bpf/task_iter.c b/kernel/bpf/task_iter.c index e791ae065c39..245f74ec491d 100644 --- a/kernel/bpf/task_iter.c +++ b/kernel/bpf/task_iter.c @@ -835,7 +835,7 @@ __bpf_kfunc int bpf_iter_task_vma_new(struct bpf_iter_t= ask_vma *it, BUILD_BUG_ON(sizeof(struct bpf_iter_task_vma_kern) !=3D sizeof(struct bpf= _iter_task_vma)); BUILD_BUG_ON(__alignof__(struct bpf_iter_task_vma_kern) !=3D __alignof__(= struct bpf_iter_task_vma)); =20 - if (!IS_ENABLED(CONFIG_PER_VMA_LOCK)) { + if (!IS_ENABLED(CONFIG_MMU)) { kit->data =3D NULL; return -EOPNOTSUPP; } diff --git a/kernel/fork.c b/kernel/fork.c index f0e2e131a9a5..ff91f5f66c80 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -1077,9 +1077,7 @@ static void mmap_init_lock(struct mm_struct *mm) { init_rwsem(&mm->mmap_lock); mm_lock_seqcount_init(mm); -#ifdef CONFIG_PER_VMA_LOCK rcuwait_init(&mm->vma_writer_wait); -#endif } =20 static struct mm_struct *mm_init(struct mm_struct *mm, struct task_struct = *p) diff --git a/mm/Kconfig b/mm/Kconfig index 331daf7fcfab..1503e2131b49 100644 --- a/mm/Kconfig +++ b/mm/Kconfig @@ -1429,18 +1429,6 @@ config LRU_GEN_WALKS_MMU depends on LRU_GEN && ARCH_HAS_HW_PTE_YOUNG # } =20 -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 diff --git a/mm/Kconfig.debug b/mm/Kconfig.debug index 5737a504efbb..1dd150edfe71 100644 --- a/mm/Kconfig.debug +++ b/mm/Kconfig.debug @@ -310,7 +310,6 @@ config DEBUG_KMEMLEAK_VERBOSE =20 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 diff --git a/mm/debug.c b/mm/debug.c index 9a0297b3988d..655e6bcc0e8d 100644 --- a/mm/debug.c +++ b/mm/debug.c @@ -157,17 +157,13 @@ void dump_vma(const struct vm_area_struct *vma) pr_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_LOCK refcount_read(&vma->vm_refcnt), -#endif vma->vm_flags, &vma->vm_flags); } EXPORT_SYMBOL(dump_vma); diff --git a/mm/init-mm.c b/mm/init-mm.c index 3e792aad7626..a1bb2c2d0284 100644 --- a/mm/init-mm.c +++ b/mm/init-mm.c @@ -39,10 +39,8 @@ struct mm_struct init_mm =3D { .page_table_lock =3D __SPIN_LOCK_UNLOCKED(init_mm.page_table_lock), .arg_lock =3D __SPIN_LOCK_UNLOCKED(init_mm.arg_lock), .mmlist =3D LIST_HEAD_INIT(init_mm.mmlist), -#ifdef CONFIG_PER_VMA_LOCK .vma_writer_wait =3D __RCUWAIT_INITIALIZER(init_mm.vma_writer_wait), .mm_lock_seq =3D SEQCNT_ZERO(init_mm.mm_lock_seq), -#endif #ifdef CONFIG_SCHED_MM_CID .mm_cid.lock =3D __RAW_SPIN_LOCK_UNLOCKED(init_mm.mm_cid.lock), #endif diff --git a/mm/memory.c b/mm/memory.c index 6ae52e3869b1..65e5fdf4f824 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -6814,7 +6814,6 @@ static vm_fault_t sanitize_fault_flags(struct vm_area= _struct *vma, !is_cow_mapping(vma->vm_flags))) 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. @@ -6823,7 +6822,6 @@ static vm_fault_t sanitize_fault_flags(struct vm_area= _struct *vma, (FAULT_FLAG_VMA_LOCK | FAULT_FLAG_RETRY_NOWAIT)) =3D=3D (FAULT_FLAG_VMA_LOCK | FAULT_FLAG_RETRY_NOWAIT))) return VM_FAULT_SIGSEGV; -#endif =20 return 0; } diff --git a/mm/mmap_lock.c b/mm/mmap_lock.c index 898c2ef1e958..e20d01e8d38f 100644 --- a/mm/mmap_lock.c +++ b/mm/mmap_lock.c @@ -43,9 +43,6 @@ void __mmap_lock_do_trace_released(struct mm_struct *mm, = bool write) EXPORT_SYMBOL(__mmap_lock_do_trace_released); #endif /* CONFIG_TRACING */ =20 -#ifdef CONFIG_MMU -#ifdef CONFIG_PER_VMA_LOCK - /* State shared across __vma_[start, end]_exclude_readers. */ struct vma_exclude_readers_state { /* Input parameters. */ @@ -431,7 +428,6 @@ struct vm_area_struct *lock_next_vma(struct mm_struct *= mm, =20 return vma; } -#endif /* CONFIG_PER_VMA_LOCK */ =20 #ifdef CONFIG_LOCK_MM_AND_FIND_VMA #include @@ -548,23 +544,3 @@ struct vm_area_struct *lock_mm_and_find_vma(struct mm_= struct *mm, 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 =3D vma_lookup(mm, addr); - if (!vma) - mmap_read_unlock(mm); - return vma; -} - -#endif /* CONFIG_MMU */ diff --git a/mm/pagewalk.c b/mm/pagewalk.c index ed4860c01936..fbcf64c59a97 100644 --- a/mm/pagewalk.c +++ b/mm/pagewalk.c @@ -446,7 +446,6 @@ static inline void process_mm_walk_lock(struct mm_struc= t *mm, 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); @@ -461,7 +460,6 @@ static inline void process_vma_walk_lock(struct vm_area= _struct *vma, /* PGWALK_RDLOCK is handled by process_mm_walk_lock */ break; } -#endif } =20 /* diff --git a/mm/rmap.c b/mm/rmap.c index b917431759ee..4e4a4b747977 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -260,11 +260,9 @@ static void check_anon_vma_clone(struct vm_area_struct= *dst, /* For the anon_vma to be compatible, it can only be singular. */ VM_WARN_ON_ONCE(operation =3D=3D 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 !=3D VMA_OP_MERGE_UNFAULTED && vma_is_attached(dst)); -#endif } =20 static void maybe_reuse_anon_vma(struct vm_area_struct *dst, diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c index 258b03182a78..edd90892f8cc 100644 --- a/mm/userfaultfd.c +++ b/mm/userfaultfd.c @@ -122,7 +122,6 @@ struct vm_area_struct *find_vma_and_prepare_anon(struct= mm_struct *mm, return vma; } =20 -#ifdef CONFIG_PER_VMA_LOCK /* * uffd_lock_vma() - Lookup and lock vma corresponding to @address. * @mm: mm to search vma in. @@ -182,34 +181,6 @@ static void uffd_mfill_unlock(struct vm_area_struct *v= ma) vma_end_read(vma); } =20 -#else - -static struct vm_area_struct *uffd_mfill_lock(struct mm_struct *dst_mm, - unsigned long dst_start, - unsigned long len) -{ - struct vm_area_struct *dst_vma; - - mmap_read_lock(dst_mm); - dst_vma =3D find_vma_and_prepare_anon(dst_mm, dst_start); - if (IS_ERR(dst_vma)) - goto out_unlock; - - if (validate_dst_vma(dst_vma, dst_start + len)) - return dst_vma; - - dst_vma =3D ERR_PTR(-ENOENT); -out_unlock: - mmap_read_unlock(dst_mm); - return dst_vma; -} - -static void uffd_mfill_unlock(struct vm_area_struct *vma) -{ - mmap_read_unlock(vma->vm_mm); -} -#endif - static void mfill_put_vma(struct mfill_state *state) { if (!state->vma) @@ -1852,7 +1823,6 @@ int find_vmas_mm_locked(struct mm_struct *mm, return 0; } =20 -#ifdef CONFIG_PER_VMA_LOCK static int uffd_move_lock(struct mm_struct *mm, unsigned long dst_start, unsigned long src_start, @@ -1927,31 +1897,6 @@ static void uffd_move_unlock(struct vm_area_struct *= dst_vma, vma_end_read(dst_vma); } =20 -#else - -static int uffd_move_lock(struct mm_struct *mm, - unsigned long dst_start, - unsigned long src_start, - struct vm_area_struct **dst_vmap, - struct vm_area_struct **src_vmap) -{ - int err; - - mmap_read_lock(mm); - err =3D find_vmas_mm_locked(mm, dst_start, src_start, dst_vmap, src_vmap); - if (err) - mmap_read_unlock(mm); - return err; -} - -static void uffd_move_unlock(struct vm_area_struct *dst_vma, - struct vm_area_struct *src_vma) -{ - mmap_assert_locked(src_vma->vm_mm); - mmap_read_unlock(dst_vma->vm_mm); -} -#endif - /** * move_pages - move arbitrary anonymous pages of an existing vma * @ctx: pointer to the userfaultfd context diff --git a/rust/kernel/mm.rs b/rust/kernel/mm.rs index 4764d7b68f2a..f4fa54616085 100644 --- a/rust/kernel/mm.rs +++ b/rust/kernel/mm.rs @@ -170,30 +170,20 @@ pub unsafe fn from_raw<'a>(ptr: *const bindings::mm_s= truct) -> &'a MmWithUser { /// /// This is an optimistic trylock operation, so it may fail if there i= s 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> { - #[cfg(CONFIG_PER_VMA_LOCK)] - { - // SAFETY: Calling `bindings::lock_vma_under_rcu` is always ok= ay given an mm where - // `mm_users` is non-zero. - let vma =3D 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 g= iven an mm where + // `mm_users` is non-zero. + let vma =3D unsafe { bindings::lock_vma_under_rcu(self.as_raw(), v= ma_addr) }; + if vma.is_null() { + return None; } - - // Silence warnings about unused variables. - #[cfg(not(CONFIG_PER_VMA_LOCK))] - let _ =3D vma_addr; - - None + Some(VmaReadGuard { + // SAFETY: If `lock_vma_under_rcu` returns a non-null ptr, the= n it points at a + // valid vma. The vma is stable for as long as the vma read lo= ck is held. + vma: unsafe { VmaRef::from_raw(vma) }, + _nts: NotThreadSafe, + }) } =20 /// Lock the mmap read lock. diff --git a/tools/testing/vma/include/dup.h b/tools/testing/vma/include/du= p.h index 800e5fa02d78..362feda28526 100644 --- a/tools/testing/vma/include/dup.h +++ b/tools/testing/vma/include/dup.h @@ -582,7 +582,6 @@ struct vm_area_struct { vma_flags_t flags; }; =20 -#ifdef CONFIG_PER_VMA_LOCK /* * Can only be written (using WRITE_ONCE()) while holding both: * - mmap_lock (in write mode) @@ -598,7 +597,7 @@ struct vm_area_struct { * slowpath. */ unsigned int vm_lock_seq; -#endif + unsigned int __vm_virt_pgoff_lo; =20 /* @@ -632,10 +631,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_virt_pgoff_hi; #endif diff --git a/tools/testing/vma/vma_internal.h b/tools/testing/vma/vma_inter= nal.h index 8a48b231aa7a..54d5c3360aa2 100644 --- a/tools/testing/vma/vma_internal.h +++ b/tools/testing/vma/vma_internal.h @@ -15,7 +15,6 @@ #include =20 #define CONFIG_MMU 1 -#define CONFIG_PER_VMA_LOCK 1 =20 #ifdef __CONCAT #undef __CONCAT --=20 2.55.0.654.g21b8a5bc05-goog From nobody Wed Sep 30 14:43:32 2026 Received: from mail-pj1-f72.google.com (mail-pj1-f72.google.com [209.85.216.72]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1661448F821 for ; Thu, 6 Aug 2026 20:05:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.72 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786046769; cv=none; b=rhn/yLjjyF4WiB9/7vzmFVf3rThg9ZqB2pkQYA4BzIADJTR8/VM4Ly6JnWAPIU9AaoXk01IjBgKS0uAmnDI8y73U4AdezBRTzh118HcFk3d0XGNd+Cbig4X6wvkH3wZjdGQMCQwuduCxCMRYpTL/WgoUlBH++xUPO41r/2OQmC8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786046769; c=relaxed/simple; bh=4yjw2zsE7pLA/X5wVKxsc5NH0WMSyFKwZIveFBbGQnc=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=TKul7GYkotLAf7p1nLSIYQ9QpGlSNcEpd0GEWYnVTZ2otOrcaEXG0FIYLu3L87ZJIsPH66lt2vvYIVIHBxja4TbcDpneGzL/k1YFKrWwnE6LN4zr35K9KB2Xgsn3EjzM2Z15SuWdcFLwEX2JUCJ57/MwDsZGfuI0FQM9Yf7DaXA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--surenb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=nsu7R9d3; arc=none smtp.client-ip=209.85.216.72 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--surenb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="nsu7R9d3" Received: by mail-pj1-f72.google.com with SMTP id 98e67ed59e1d1-38ecc48b3c2so3674905a91.1 for ; Thu, 06 Aug 2026 13:05:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1786046756; x=1786651556; darn=vger.kernel.org; h=content-transfer-encoding:content-type:cc:to:from:subject :message-id:references:mime-version:in-reply-to:date:from:to:cc :subject:date:message-id:reply-to:content-type; bh=myw2oDUjCx3VpKcfHammnirgTkZxfVTM2uRSXVRFIyw=; b=nsu7R9d3bYSUsNSYKO9jwj47dB1QV+W0VAZi+JivXuIxyODm7RO7AFWcssnaTRrwxx Gg6c19gGOS1Wqi2qv5DUklx5Lo5Ivb8RYzbQa8Pen+8uPFYX9p+OT6SyoyepyIXq9u5c m1weamEblrhO5J/vhdFVJcMCPVXJ0SraBjVp5qd/HBG0O+zTnB31trFp2yWj+cSfQxKa 95b5Pde8eUFHqkXaXIME0g2NsyyuNP2IX4yVKGNm6Af67wETsllF7XfFebFxd5YSZfYh CMKAaRHZ6m6zjR3D5b+ITn5FZ/mi4x5n9DgnCI6URlYHLEO0LOGmJ9smUomntkEkFqmu 7HgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786046756; x=1786651556; h=content-transfer-encoding:content-type:cc:to:from:subject :message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=myw2oDUjCx3VpKcfHammnirgTkZxfVTM2uRSXVRFIyw=; b=RBx0h/rmzpW9km/3NfyAVldAUHV/9INQ9lRHSiQ6ywCudwuoks1uzh/A5KvIFSGrmd OZlebumL3u8ky6Q54K45uO22fHJozpv3DRtHMMYtxcfs+AesCScLEjfbnUPPe6LHutup vK27CewYKkiqZepBJKL6/JB1gV7FndXRkCsls7UCCKldIP+9PDy2u09+WfcFbet958jb 46WiCnddJkiXoEMxBCD8CtJ/oZ0ekqvolFXu3D0jp25+GKkLnbtgeQO5jUHAAYCen+t5 R9UUilaUqx5rXUzmd/2F4R4sm0ct7y9NzYEg37mQV2HSDfpcdULEL9B6c+DifXRs74Is QZZw== X-Forwarded-Encrypted: i=1; AHgh+RoMV1h5UkpwBHBP/Hi6BoaOd6VKwaYqKttWjlJNACAYbTpjpkO72oIo7c+hJ5c590OjD+lKu4IDJvBZbrY=@vger.kernel.org X-Gm-Message-State: AOJu0YwIzvd4vTzf1upunTjU5Kcz8FbxWcWE0fjWVrXkOaFNOLbKyG1w 3Wsq0JSPTa81+hn26eSngpCWmUllwhmX7GcQjT7tQBE67t6DEL/kI4N56wOqisVCeKc2uw7EaV4 72D3hpg== X-Received: from dlam21-n2.prod.google.com ([2002:a05:701b:2095:20b0:13c:f3ec:de27]) (user=surenb job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:2d50:b0:380:f34a:6ff1 with SMTP id 98e67ed59e1d1-3903c5e0213mr17427991a91.17.1786046755489; Thu, 06 Aug 2026 13:05:55 -0700 (PDT) Date: Thu, 6 Aug 2026 13:05:45 -0700 In-Reply-To: <20260806200548.3124802-1-surenb@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260806200548.3124802-1-surenb@google.com> X-Mailer: git-send-email 2.55.0.654.g21b8a5bc05-goog Message-ID: <20260806200548.3124802-3-surenb@google.com> Subject: [PATCH v4 2/5] binder: Make shrinker rely solely on per-VMA lock From: Suren Baghdasaryan To: akpm@linux-foundation.org Cc: dave.hansen@linux.intel.com, Liam.Howlett@oracle.com, ljs@kernel.org, david@kernel.org, willy@infradead.org, shakeel.butt@linux.dev, vbabka@kernel.org, jannh@google.com, aliceryhl@google.com, arve@android.com, cmllamas@google.com, christian@brauner.io, tkjos@android.com, dsahern@kernel.org, davem@davemloft.net, gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, netdev@vger.kernel.org, surenb@google.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Dave Hansen tl;dr: lock_vma_under_rcu() is already a trylock. No need to do both it and mmap_read_trylock(). Long Version: =3D=3D Background =3D=3D Historically, binder used an mmap_read_trylock() in its shrinker code. This ensures that reclaim is not blocked on an mmap_lock. Commit 95bc2d4a9020 ("binder: use per-vma lock in page reclaiming") added support for the per-VMA lock, but left mmap_read_trylock() as a fallback. This was presumably because the per-VMA locking can fail for several reasons and most (all?) lock_vma_under_rcu() callers have a fallback to mmap_read_trylock(). =3D=3D Problem =3D=3D The fallback is not worth the complexity here. lock_vma_under_rcu() is essentially already a non-blocking trylock. The main reason it fails is also the reason mmap_read_trylock() fails: something is holding mmap_write_lock(). The only remedy for a collision with mmap_write_lock() is to wait, which this code can not do. So the "fallback" after lock_vma_under_rcu() failure is not really a fallback: it is really likely to just be retrying in vain. That retry in an of itself isn't horrible. But it adds complexity. =3D=3D Solution =3D=3D Now that per-VMA locks are universally available, lock_vma_under_rcu() will not persistently fail. Rely on it alone and simplify the code. The removal of the fallback does not affect NOMMU case because binder driver depends on CONFIG_MMU. Full disclosure: I originally tried to do this with lock_vma_under_rcu_wait(), but it did not fit well with the mmap_lock trylock semantics. Claude caught this in a review and suggested the approach in this path. It seemed sane to me. So, Suggesed-by: Claude, I guess. Signed-off-by: Dave Hansen Signed-off-by: Suren Baghdasaryan Cc: Andrew Morton Cc: "Liam R. Howlett" Cc: Vlastimil Babka Cc: Shakeel Butt Cc: linux-mm@kvack.org Cc: Greg Kroah-Hartman Cc: Arve Hj=C3=B8nnev=C3=A5g Cc: Todd Kjos Cc: Christian Brauner Cc: Carlos Llamas Cc: Alice Ryhl Cc: "David S. Miller" Cc: David Ahern Cc: netdev@vger.kernel.org Acked-by: Lorenzo Stoakes (ARM) Reviewed-by: Alice Ryhl --- drivers/android/binder_alloc.c | 45 ++++++++++++++++------------------ 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/drivers/android/binder_alloc.c b/drivers/android/binder_alloc.c index e4488ad86a65..c13a588c37de 100644 --- a/drivers/android/binder_alloc.c +++ b/drivers/android/binder_alloc.c @@ -1142,7 +1142,6 @@ enum lru_status binder_alloc_free_page(struct list_he= ad *item, struct vm_area_struct *vma; struct page *page_to_free; unsigned long page_addr; - int mm_locked =3D 0; size_t index; =20 if (!mmget_not_zero(mm)) @@ -1151,27 +1150,25 @@ enum lru_status binder_alloc_free_page(struct list_= head *item, index =3D mdata->page_index; page_addr =3D alloc->vm_start + index * PAGE_SIZE; =20 - /* attempt per-vma lock first */ + /* + * Attempt per-vma lock. This is essentially a + * "trylock". It can fail even if the VMA exists + * for 'page_addr'. + */ vma =3D lock_vma_under_rcu(mm, page_addr); if (!vma) { - /* fall back to mmap_lock */ - if (!mmap_read_trylock(mm)) - goto err_mmap_read_lock_failed; - mm_locked =3D 1; - vma =3D vma_lookup(mm, page_addr); + /* + * If the vma exists, we can't continue because we cannot + * remove the page from the vma. However, if the vma was + * unmapped, it's okay to continue. + */ + if (binder_alloc_is_mapped(alloc)) + goto err_vma_lock_failed; } =20 if (!mutex_trylock(&alloc->mutex)) goto err_get_alloc_mutex_failed; =20 - /* - * Since a binder_alloc can only be mapped once, we ensure - * the vma corresponds to this mapping by checking whether - * the binder_alloc is still mapped. - */ - if (vma && !binder_alloc_is_mapped(alloc)) - goto err_invalid_vma; - trace_binder_unmap_kernel_start(alloc, index); =20 page_to_free =3D alloc->pages[index]; @@ -1182,7 +1179,12 @@ enum lru_status binder_alloc_free_page(struct list_h= ead *item, list_lru_isolate(lru, item); spin_unlock(&lru->lock); =20 - if (vma) { + /* + * Since a binder_alloc can only be mapped once, we ensure + * the vma corresponds to this mapping by checking whether + * the binder_alloc is still mapped. + */ + if (vma && binder_alloc_is_mapped(alloc)) { trace_binder_unmap_user_start(alloc, index); =20 zap_vma_range(vma, page_addr, PAGE_SIZE); @@ -1191,23 +1193,18 @@ enum lru_status binder_alloc_free_page(struct list_= head *item, } =20 mutex_unlock(&alloc->mutex); - if (mm_locked) - mmap_read_unlock(mm); - else + if (vma) vma_end_read(vma); mmput_async(mm); binder_free_page(page_to_free); =20 return LRU_REMOVED_RETRY; =20 -err_invalid_vma: mutex_unlock(&alloc->mutex); err_get_alloc_mutex_failed: - if (mm_locked) - mmap_read_unlock(mm); - else + if (vma) vma_end_read(vma); -err_mmap_read_lock_failed: +err_vma_lock_failed: mmput_async(mm); err_mmget: return LRU_SKIP; --=20 2.55.0.654.g21b8a5bc05-goog From nobody Wed Sep 30 14:43:32 2026 Received: from mail-pg1-f198.google.com (mail-pg1-f198.google.com [209.85.215.198]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ED06B3B4EA9 for ; Thu, 6 Aug 2026 20:06:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.198 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786046772; cv=none; b=e+5O7fl2qDzzOtjz4uaYd3K7u6CoRVbrZfCtUV0Fgctq4XcrTGge99wKnRxjsTyubRG83dnfOYpVlKGAUxS2MeTtizyAtpAmETCXZRqWxvye+CykVzanKgsydmtyAThT5W7OZL5LglFSJ/7fz+bOdbPNOjlOIKMj0W6ek0fhLNk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786046772; c=relaxed/simple; bh=mUqZ7Veb1zFzK/WMrx+J1dlL4u1EqvbVFzzSi64rsvk=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=cBogWH3vXJPcxSWvnPC8oGoXZAiqGPFriLV0Z27RtUgr2mISuFUBJRN7U2V1gtxoxeFjKut26XbVX2jLEju6d9dUcC31lfYWGwmQ4LhJ6fEJMD92SdbBmXtmwZJQiWNtHKO2knYt99QyMbhTKyuswQ2vVL/I5rVT8AiWZTanO6M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--surenb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=vVw/f90+; arc=none smtp.client-ip=209.85.215.198 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--surenb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="vVw/f90+" Received: by mail-pg1-f198.google.com with SMTP id 41be03b00d2f7-cbb6433e9d4so3209551a12.3 for ; Thu, 06 Aug 2026 13:06:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1786046758; x=1786651558; darn=vger.kernel.org; h=content-transfer-encoding:content-type:cc:to:from:subject :message-id:references:mime-version:in-reply-to:date:from:to:cc :subject:date:message-id:reply-to:content-type; bh=WxdxEYaVQTOzSX1A2H67ZbXWMmNc4RyRDurH1LCMnVo=; b=vVw/f90+obTFzPKFfsClGu3kRPwL03UYt0y8dKQWUHgprYyT3RrxOSft8u83bV+4K3 sLuP3wPdE28F0pGcoG2U3RuEwPIXBWGGGsc9O4Zo6Lqrq1gnQm/lM0vHTAlY6ed/HE0y 9EFt7zeGJV9oenBKy10KV0pCpm2cbbxWiINk/IlsZqAwh8CVCPNZhRG085ktxsu7jRrC 5rUeQSDUTkLwfTeyQN0hmcXk6Bk3Hu/FhD40Gm01uip0MWy127GrVI55UzbEhd4sMnFK M2e4CUalx+tNxau7InZ1lLHsdrD/PY5pBZ26TOWcxu30fDmjyFyqzcq2yMdPFygEcK2k 2FtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786046758; x=1786651558; h=content-transfer-encoding:content-type:cc:to:from:subject :message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=WxdxEYaVQTOzSX1A2H67ZbXWMmNc4RyRDurH1LCMnVo=; b=h2pWzFrMTX5LvIVtbkfgkd8qhjgMcP2S32erZfQMIvTRzUNVH39EyncQm7bxhCxCAi N2bhE0XGDOppMuVdpDm/19uwh/EpTiYxVaZlEa4bchYlgkZtM3a84IrIrVoQAGimAHRg +eputEA3kiyjloRMA/dazLuMo4Nldyr7GpjioJp4wxCoU0v1XK1HudbBbQUkN/U4NM/0 6YndNt4bLVrsuwk8wzb8xUtHC4ygONANwcxt6HyeNec4N9DksFDy2nPT6OHjsQnhYZFV 8p9xcHzFGnBrvpgwrqMwlWQNkJtbS/48q3R6XirtWrVB1xJQPyG5GldhR1CPOd1Aflj+ cUsg== X-Forwarded-Encrypted: i=1; AHgh+RpmZY/Od625YC6ZgrxuAExcTVCQ6UEzAQWkBuRKoVdD319cLvsy3uzn6GEuw/hM+80tra1Rslt9bDM+7sw=@vger.kernel.org X-Gm-Message-State: AOJu0Yx9zgQSImA1TlS6SS6jOC/6ihvzCRzjIky69vuvEiAh1iFOQI9a AbYqK2qrcaAxleep36Cip2kH0vcmjf9ekt/RpEqDLH4x/w9GnYBKm97lGLcwHZDI08+WzUqkzFU iPdQLtQ== X-Received: from dybgk24.prod.google.com ([2002:a05:7301:198:b0:313:cf3c:796]) (user=surenb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:6a03:b0:398:8870:b58f with SMTP id adf61e73a8af0-3cb85de7ddbmr20267974637.14.1786046757653; Thu, 06 Aug 2026 13:05:57 -0700 (PDT) Date: Thu, 6 Aug 2026 13:05:46 -0700 In-Reply-To: <20260806200548.3124802-1-surenb@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260806200548.3124802-1-surenb@google.com> X-Mailer: git-send-email 2.55.0.654.g21b8a5bc05-goog Message-ID: <20260806200548.3124802-4-surenb@google.com> Subject: [PATCH v4 3/5] mm: Add RCU-based VMA lookup helper that waits for writers From: Suren Baghdasaryan To: akpm@linux-foundation.org Cc: dave.hansen@linux.intel.com, Liam.Howlett@oracle.com, ljs@kernel.org, david@kernel.org, willy@infradead.org, shakeel.butt@linux.dev, vbabka@kernel.org, jannh@google.com, aliceryhl@google.com, arve@android.com, cmllamas@google.com, christian@brauner.io, tkjos@android.com, dsahern@kernel.org, davem@davemloft.net, gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, netdev@vger.kernel.org, surenb@google.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Dave Hansen =3D=3D Background =3D=3D There are basically two parallel ways to look up a VMA: the traditional way, which is protected by mmap_read_lock, and the RCU-based per-VMA lock way which is based on RCU and refcounts. =3D=3D Problem =3D=3D The mmap_lock one is more straightforward to use but it has a big disadvantage in that it can not be mixed with page faults since those can take mmap_lock for read, which can deadlock when mixed with nested page faults and parallel writers. For example: mmap_read_lock(mm); // Another thread does mmap_write_lock(). // New mmap_lock readers are blocked. vma =3D vma_lookup(mm, address); // This deadlocks on mmap_read_lock() if it faults: copy_from_user(address); mmap_read_unlock(mm); The per-VMA lock can be mixed with faults, but they can fail and need to be able to fall back to the traditional way. =3D=3D Solution =3D=3D Add vma_start_read_unlocked() - a variant of the RCU-based lookup that waits for writers. This is basically the same as the existing RCU-based lookup, but on a failure to lock it temporarily takes mmap_lock for read and waits for writers to finish before locking the VMA, dropping the mmap_lock and returning the locked VMA. This has some advantages: 1. Callers do not need to have a fallback path for when they collide with writers. 2. It can be used in contexts where page faults can happen because it can take the mmap_lock for read but never *holds* it. 3. Its fast path does not require taking mmap_lock for read. Basically, when applied correctly, this approach results in faster *and* simpler code. While at it, fix the comments for vma_start_read_locked(), vma_start_read_locked_nested(), and uffd_lock_vma(). Suggested-by: Lorenzo Stoakes (ARM) Signed-off-by: Dave Hansen Signed-off-by: Suren Baghdasaryan Cc: Suren Baghdasaryan Cc: Andrew Morton Cc: "Liam R. Howlett" Cc: Lorenzo Stoakes Cc: Vlastimil Babka Cc: Shakeel Butt Cc: linux-mm@kvack.org Cc: Greg Kroah-Hartman Cc: Arve Hj=C3=B8nnev=C3=A5g Cc: Todd Kjos Cc: Christian Brauner Cc: Carlos Llamas Cc: Alice Ryhl Cc: "David S. Miller" Cc: David Ahern Cc: netdev@vger.kernel.org Acked-by: Vlastimil Babka (SUSE) Reviewed-by: Lorenzo Stoakes (ARM) --- include/linux/mmap_lock.h | 19 +++++++++++++++---- mm/mmap_lock.c | 35 +++++++++++++++++++++++++++++++++++ mm/userfaultfd.c | 6 ++++-- 3 files changed, 54 insertions(+), 6 deletions(-) diff --git a/include/linux/mmap_lock.h b/include/linux/mmap_lock.h index 7b2bbb09a952..a23fe6cbe301 100644 --- a/include/linux/mmap_lock.h +++ b/include/linux/mmap_lock.h @@ -228,10 +228,14 @@ static inline void vma_refcount_put(struct vm_area_st= ruct *vma) } =20 /* - * Use only while holding mmap read lock which guarantees that locking wil= l not - * fail (nobody can concurrently write-lock the vma). vma_start_read() sho= uld + * Use only while holding mmap read lock which guarantees that vma lock is= not + * contended (nobody can concurrently write-lock the vma). vma_start_read(= ) should * not be used in such cases because it might fail due to mm_lock_seq over= flow. * This functionality is used to obtain vma read lock and drop the mmap re= ad lock. + * + * VMA can't be detached while we are holding mmap lock, therefore in prac= tice this + * function can fail only when there are so many readers that vm_refcnt ov= erflows. + * The failure case is very unlikely and is already annotated as such inte= rnally. */ static inline bool vma_start_read_locked_nested(struct vm_area_struct *vma= , int subclass) { @@ -247,16 +251,23 @@ static inline bool vma_start_read_locked_nested(struc= t vm_area_struct *vma, int } =20 /* - * Use only while holding mmap read lock which guarantees that locking wil= l not - * fail (nobody can concurrently write-lock the vma). vma_start_read() sho= uld + * Use only while holding mmap read lock which guarantees that vma lock is= not + * contended (nobody can concurrently write-lock the vma). vma_start_read(= ) should * not be used in such cases because it might fail due to mm_lock_seq over= flow. * This functionality is used to obtain vma read lock and drop the mmap re= ad lock. + * + * VMA can't be detached while we are holding mmap lock, therefore in prac= tice this + * function can fail only when there are so many readers that vm_refcnt ov= erflows. + * The failure case is very unlikely and is already annotated as such inte= rnally. */ static inline bool vma_start_read_locked(struct vm_area_struct *vma) { return vma_start_read_locked_nested(vma, 0); } =20 +struct vm_area_struct *vma_start_read_unlocked(struct mm_struct *mm, + unsigned long address); + static inline void vma_end_read(struct vm_area_struct *vma) { vma_refcount_put(vma); diff --git a/mm/mmap_lock.c b/mm/mmap_lock.c index e20d01e8d38f..1c4902131e98 100644 --- a/mm/mmap_lock.c +++ b/mm/mmap_lock.c @@ -338,6 +338,41 @@ struct vm_area_struct *lock_vma_under_rcu(struct mm_st= ruct *mm, return NULL; } =20 +/** + * vma_start_read_unlocked() - Find the VMA covering 'address' and read-lo= ck it. + * @mm: the mm_struct of the address space to search + * @address: address that the vma should contain + * + * The fast path does not take mmap_lock. Waits for writers to finish if t= he + * VMA is being modified by taking mmap_lock. + * Use when mmap_lock is not held, otherwise use vma_start_read_locked(). + * Nothing prevents VMAs being unmapped/mapped before or after the VMA is + * looked up, if a stronger guarantee is required, take an mmap_lock. + * + * Return: If a VMA exists which spans @address, return that VMA, read-loc= ked. + * If no VMA is mapped there or, very unlikely, a reference count overflow + * occurred, return NULL. + */ +struct vm_area_struct *vma_start_read_unlocked(struct mm_struct *mm, + unsigned long address) +{ + struct vm_area_struct *vma; + + /* Fast path: return stable VMA covering 'address': */ + vma =3D lock_vma_under_rcu(mm, address); + if (vma) + return vma; + + /* Slow path: preclude VMA writers by temporarily getting mmap read lock.= */ + mmap_read_lock(mm); + vma =3D vma_lookup(mm, address); + if (vma && !vma_start_read_locked(vma)) + vma =3D NULL; + mmap_read_unlock(mm); + + return vma; +} + static struct vm_area_struct *lock_next_vma_under_mmap_lock(struct mm_stru= ct *mm, struct vma_iterator *vmi, unsigned long from_addr) diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c index edd90892f8cc..c3a0c38a3dc3 100644 --- a/mm/userfaultfd.c +++ b/mm/userfaultfd.c @@ -129,8 +129,10 @@ struct vm_area_struct *find_vma_and_prepare_anon(struc= t mm_struct *mm, * * Should be called without holding mmap_lock. * - * Return: A locked vma containing @address, -ENOENT if no vma is found, or - * -ENOMEM if anon_vma couldn't be allocated. + * Return: A locked vma containing @address, -ENOENT if no vma is found, + * -ENOMEM if anon_vma couldn't be allocated, or -EAGAIN if vma refcount + * overflow happened due to high number of readers and the caller should + * retry later. */ static struct vm_area_struct *uffd_lock_vma(struct mm_struct *mm, unsigned long address) --=20 2.55.0.654.g21b8a5bc05-goog From nobody Wed Sep 30 14:43:32 2026 Received: from mail-pg1-f199.google.com (mail-pg1-f199.google.com [209.85.215.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F22C0494824 for ; Thu, 6 Aug 2026 20:06:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.199 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786046770; cv=none; b=P4hjO+1E3Kp/Fa62zuhQ39o/P79sFmRDN8uB58GcS6sWjIDJrz9ReGb96bnznWdw1jgKgmG8HGnMmNPep+INDD7C4V0FZB0v+zjSr4MnlDfEIv3A39wSNDgnnDtckYBoOJRV525M80khL5VOgd1D67SMSYTPo0bVF9z+LOAgFOM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786046770; c=relaxed/simple; bh=xPo0ALC5GAD0pJpjspQena11dKnVnoOGrSo0u0zS+80=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=n4Q4bUTijEfLSHux3e8hP6rFfiVDjqkI+6B48TDPP19qhbPUpcRcpzpCWM9w5l+lVuXQkIBH3YOE+wrEAFsQ3lB40m5lBAcBdyWt0z4nhARMb1EuJ8Hn6fPBeNIwd5xUbTwh58XIt0bMQuLlE/TDkq1s/AwsRzsjK8a+nz2nVLo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--surenb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=cv9A0Cfe; arc=none smtp.client-ip=209.85.215.199 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--surenb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="cv9A0Cfe" Received: by mail-pg1-f199.google.com with SMTP id 41be03b00d2f7-c88cfe287e1so2091129a12.1 for ; Thu, 06 Aug 2026 13:06:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1786046760; x=1786651560; darn=vger.kernel.org; h=content-transfer-encoding:content-type:cc:to:from:subject :message-id:references:mime-version:in-reply-to:date:from:to:cc :subject:date:message-id:reply-to:content-type; bh=qo+gPZDCnzT8MahhMkr4ixbPoS7BupzxB9Ai/ylfWm8=; b=cv9A0CfeC03ES9ME+CswT47xH3un2xsmUiOMSkw+jsYfh25rBH70jTRk1j6IpMKy7q tApECJgoG4fgLyMNUZBuQ1GHR144DEQNZi7Y4N2NUR+diswxppM+8GkUOyaWvjlMmvXs /0BzBjuI0+ZonkjHrmuCciW90gKB5Ka7WAhvuM44L8i2kcr7Xcdsx5+K0mkeqc5SIM2I C+718/WEJLVfRoAjEwfA8ah9WY3sii3ZmxdQWhz+6rkD+l5UxpJHpgvJFjDEiOEETK1b l5FYPN21Sd7rdhtYAUjQap+FqNCfaRS30QDr+VRZrO8FbPADiO8wSCxSULWFNsH5UXqW eAyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786046760; x=1786651560; h=content-transfer-encoding:content-type:cc:to:from:subject :message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=qo+gPZDCnzT8MahhMkr4ixbPoS7BupzxB9Ai/ylfWm8=; b=cmtEOne8eAXXNVDHsIP8QVKfdbC8k6uKbKXz2BtFG4YRPBPfvfnmvbsBSTcj3PisSg whxxpgNDmMNfeFVWEy8ymQUuWmdwgYDTwZn0Y45vmGFva6te8CK0UMXlSZTauArPu2lF jCYFEAVy1n/FY3ASXgHpq7SQM7lJsla1dRxW8BvraPXs44OwiKwx2DHau9W7WeSGIr38 04w2W72L6QqcMRVzKVIQTOJ3VNKasu8cNGJQBOSdkpYQ9Y8FZwXQBk6jEfy1sVCGCqn5 PEJizO+0W9ysr3L3NtktRhVhPc8eDiOAzCSoeS/Vo2nzrzgcqw+SWaPOkjdQ11BNO/GY tnRQ== X-Forwarded-Encrypted: i=1; AHgh+RoJE83P5GkECgQ86wMuY1kNqLXQJmdR2GhUWwcSltBPp/pZRbokCO0R4Emd1d7MUe96+xN2JJ4gfs/O0fM=@vger.kernel.org X-Gm-Message-State: AOJu0Yy9xYK7aAguuU3Q3F2wrtO2CIRf2O9z41z6+Ggf+fDErUBVdxbQ zx2cMnvyOxCEBlp+hdou3ktrNxaQtz1RUuGlXX5FEVzu/rbL28dbFM6jjPeHMcR2r9nhx+p0Pxf 1XS4ryA== X-Received: from dybqh4.prod.google.com ([2002:a05:7301:6244:b0:30c:83f3:7370]) (user=surenb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:6daa:b0:3c4:3672:ba6 with SMTP id adf61e73a8af0-3cbadc15329mr4732449637.22.1786046759808; Thu, 06 Aug 2026 13:05:59 -0700 (PDT) Date: Thu, 6 Aug 2026 13:05:47 -0700 In-Reply-To: <20260806200548.3124802-1-surenb@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260806200548.3124802-1-surenb@google.com> X-Mailer: git-send-email 2.55.0.654.g21b8a5bc05-goog Message-ID: <20260806200548.3124802-5-surenb@google.com> Subject: [PATCH v4 4/5] binder: Remove mmap_lock fallback From: Suren Baghdasaryan To: akpm@linux-foundation.org Cc: dave.hansen@linux.intel.com, Liam.Howlett@oracle.com, ljs@kernel.org, david@kernel.org, willy@infradead.org, shakeel.butt@linux.dev, vbabka@kernel.org, jannh@google.com, aliceryhl@google.com, arve@android.com, cmllamas@google.com, christian@brauner.io, tkjos@android.com, dsahern@kernel.org, davem@davemloft.net, gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, netdev@vger.kernel.org, surenb@google.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Dave Hansen Previously, the per-VMA locking could fail in the face of writers which necessitate a fallback to mmap_lock. The new vma_start_read_unlocked() will wait for writers instead of failing. Use the new helper. Wait for writers. Remove the fallback to mmap_lock. Signed-off-by: Dave Hansen Signed-off-by: Suren Baghdasaryan Reviewed-by: Alice Ryhl Acked-by: Lorenzo Stoakes (ARM) Cc: Andrew Morton Cc: Liam R. Howlett Cc: Vlastimil Babka Cc: Shakeel Butt Cc: linux-mm@kvack.org Cc: Greg Kroah-Hartman Cc: Arve Hj=C3=B8nnev=C3=A5g Cc: Todd Kjos Cc: Christian Brauner Cc: Carlos Llamas Cc: Alice Ryhl Cc: David S. Miller Cc: David Ahern Cc: netdev@vger.kernel.org --- drivers/android/binder/page_range.rs | 19 +++---------------- drivers/android/binder_alloc.c | 17 +++++------------ rust/kernel/mm.rs | 27 +++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 28 deletions(-) diff --git a/drivers/android/binder/page_range.rs b/drivers/android/binder/= page_range.rs index e82a5523804f..f7ad88a0d806 100644 --- a/drivers/android/binder/page_range.rs +++ b/drivers/android/binder/page_range.rs @@ -439,22 +439,9 @@ unsafe fn use_page_slow(&self, i: usize) -> Result<()>= { // workqueue. let mm =3D MmWithUser::into_mmput_async(self.mm.mmget_not_zero().o= k_or(ESRCH)?); { - let vma_read; - let mmap_read; - let vma =3D if let Some(ret) =3D mm.lock_vma_under_rcu(vma_add= r) { - vma_read =3D ret; - check_vma(&vma_read, self) - } else { - mmap_read =3D mm.mmap_read_lock(); - mmap_read - .vma_lookup(vma_addr) - .and_then(|vma| check_vma(vma, self)) - }; - - match vma { - Some(vma) =3D> vma.vm_insert_page(user_page_addr, &new_pag= e)?, - None =3D> return Err(ESRCH), - } + let vma_read_guard =3D mm.vma_start_read_unlocked(vma_addr).ok= _or(ESRCH)?; + let vma =3D check_vma(&vma_read_guard, self).ok_or(ESRCH)?; + vma.vm_insert_page(user_page_addr, &new_page)?; } =20 let inner =3D self.lock.lock(); diff --git a/drivers/android/binder_alloc.c b/drivers/android/binder_alloc.c index c13a588c37de..efa23f6b8360 100644 --- a/drivers/android/binder_alloc.c +++ b/drivers/android/binder_alloc.c @@ -259,21 +259,14 @@ static int binder_page_insert(struct binder_alloc *al= loc, struct vm_area_struct *vma; int ret =3D -ESRCH; =20 - /* attempt per-vma lock first */ - vma =3D lock_vma_under_rcu(mm, addr); - if (vma) { - if (binder_alloc_is_mapped(alloc)) - ret =3D vm_insert_page(vma, addr, page); - vma_end_read(vma); + vma =3D vma_start_read_unlocked(mm, addr); + if (!vma) return ret; - } =20 - /* fall back to mmap_lock */ - mmap_read_lock(mm); - vma =3D vma_lookup(mm, addr); - if (vma && binder_alloc_is_mapped(alloc)) + if (binder_alloc_is_mapped(alloc)) ret =3D vm_insert_page(vma, addr, page); - mmap_read_unlock(mm); + + vma_end_read(vma); =20 return ret; } diff --git a/rust/kernel/mm.rs b/rust/kernel/mm.rs index f4fa54616085..11466fb304df 100644 --- a/rust/kernel/mm.rs +++ b/rust/kernel/mm.rs @@ -186,6 +186,33 @@ pub fn lock_vma_under_rcu(&self, vma_addr: usize) -> O= ption> { }) } =20 + /// Find the VMA covering 'address' and read-lock it. + /// + /// The fast path does not take mmap_lock. Waits for writers to finish= if the + /// VMA is being modified by taking mmap_lock. + /// Use when mmap_lock is not held, otherwise use vma_start_read_locke= d(). + /// Nothing prevents VMAs being unmapped/mapped before or after the VM= A is + /// looked up, if a stronger guarantee is required, take an mmap_lock. + /// + /// Return: If a VMA exists which spans @address, return that VMA, rea= d-locked. + /// If no VMA is mapped there or, very unlikely, a reference count ove= rflow + /// occurred, return NULL. + #[inline] + pub fn vma_start_read_unlocked(&self, vma_addr: usize) -> Option> { + // SAFETY: We may invoke `vma_start_read_unlocked` because we know= this `mm` has non-zero + // `mm_users`. + let vma =3D unsafe { bindings::vma_start_read_unlocked(self.as_raw= (), vma_addr) }; + if vma.is_null() { + return None; + } + Some(VmaReadGuard { + // SAFETY: If `vma_start_read_unlocked` returns a non-null ptr= , then it points at a + // valid vma. The vma is stable for as long as the vma read lo= ck is held. + vma: unsafe { VmaRef::from_raw(vma) }, + _nts: NotThreadSafe, + }) + } + /// Lock the mmap read lock. #[inline] pub fn mmap_read_lock(&self) -> MmapReadGuard<'_> { --=20 2.55.0.654.g21b8a5bc05-goog From nobody Wed Sep 30 14:43:32 2026 Received: from mail-pg1-f199.google.com (mail-pg1-f199.google.com [209.85.215.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 22609488D9C for ; Thu, 6 Aug 2026 20:06:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.199 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786046772; cv=none; b=INgzomxkcGQyhZnjiCYtU+xUNYUKndbEiHivrRd1sQQD2V1+37tX/sAbzhtU1h6Xb5Efu0nRyuqVt3D7D7mCThzyoWyaOhFnZDvM+TTuiGSZHRp9P1I9p3tw8/0xZnUHbgFngcipUhRpy9lmrB7TwwHCnTdkQzOJR9BUeVbLG2Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786046772; c=relaxed/simple; bh=TPi0HX2ysFtmGcnCVFDQsVS2ZyLYaf8xLB2ebNG9mOI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=AJeH1Rq9f+iOkFE8xmI/dYD1gqvx+KQm9ehaG1rgcN6Wp9wt76FORa99WiTtUI9ND7usJj79JxfuA99bgwHZREGv4hYYpOyNJagUk55ZES7EC6uVvNTPcXO3ZJsCzMzZqNHwpUl+xSdgdkBGsP45ONVmOxqg38U8VT3RSrNWiRA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--surenb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=hpS44DOr; arc=none smtp.client-ip=209.85.215.199 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--surenb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="hpS44DOr" Received: by mail-pg1-f199.google.com with SMTP id 41be03b00d2f7-ca124bf0189so1049720a12.0 for ; Thu, 06 Aug 2026 13:06:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1786046763; x=1786651563; darn=vger.kernel.org; h=content-transfer-encoding:content-type:cc:to:from:subject :message-id:references:mime-version:in-reply-to:date:from:to:cc :subject:date:message-id:reply-to:content-type; bh=FBBPYUiw+wGnA3pW6euCqNL/2cPXXNetrkceEEdDJ4M=; b=hpS44DOr2zunUyEdaAMcKvOltrwHWaXiTJjDM3ugaWYV12Svs08N2FpBI3/UYEUV8K 0mNRAwcKNa7czncq/LBMXy5s+/4UrIHvFe5aGRauwaKNMcyRkObJc9i+Lvpz47Mk5Anm +vbtaHitC6Ro2COJrgBabl7YeBiMnl947PIvlnVs8zoMGd9Np/HtUZQ0gzMKZx1A7Ycs CzdArs+E2Qy4LPvpAhCX5Y4+yTe06vafVadghmE4gN2GAcF/E7mAfp2zI7x4d+k+DDlF /fZdz9L+i8pp2dYekpkYYG+x2R7pgR8a8+gaZRCleA7bVXTDlMKD1h1JxOojbdCfsWf9 x9+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786046763; x=1786651563; h=content-transfer-encoding:content-type:cc:to:from:subject :message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=FBBPYUiw+wGnA3pW6euCqNL/2cPXXNetrkceEEdDJ4M=; b=hip2pIEz19u76hsvHIYJePVF5mf4E1aPOV7HZ5rRVB3KkwORA61F/e6XW8/AiePWtX wFyla4seGCqoJx7c7gQF4PskZf7Ry8azncA9Hcp+Ss09dHVajAkzLYDomAzushAZHiw0 UT9B5YP/Uea10Y3LASBqNO3KjTX3WpnBqwQRPIJdU5NgTXzeae2NRiaSllGpaLOdRK5y 0eUJuozXHe/6dqsp0zNwibTH4tflyM+5RfvG0EzzuLPjkhETgnjDs0gLD1d8vJVevqKI vrkyK9lMAamA6snAxZ5vlT5PMa8I5J5hkw+sN+eGA6d0yCAYH7eEbrFQXppx/1AAFvtM 6uPQ== X-Forwarded-Encrypted: i=1; AHgh+RqIr3mrbZtt2Pqn8hBcD7XxZoRPkkPComen52vxp1ar+iWiGSaEiSNRUnXtDDNFD3XXOdlrjhAEKNdWeAk=@vger.kernel.org X-Gm-Message-State: AOJu0YxD1qQRoSTtY8o7zgH0smbDyqsO8Y/fFgi4Z3IXKQ0VbK4cFX84 +jHYj7Vtcy1qis892iN01tgX0MstwYR34TxcNuQeY0OmvIWSH0ZYfAvsHN/UxYMsCxDxGcQ27w9 Dmawh9A== X-Received: from dlea14-n1.prod.google.com ([2002:a05:701b:420e:10b0:13d:31db:8d94]) (user=surenb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:914f:b0:3b3:a66e:3911 with SMTP id adf61e73a8af0-3cb9c2c4782mr8716046637.19.1786046762261; Thu, 06 Aug 2026 13:06:02 -0700 (PDT) Date: Thu, 6 Aug 2026 13:05:48 -0700 In-Reply-To: <20260806200548.3124802-1-surenb@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260806200548.3124802-1-surenb@google.com> X-Mailer: git-send-email 2.55.0.654.g21b8a5bc05-goog Message-ID: <20260806200548.3124802-6-surenb@google.com> Subject: [PATCH v4 5/5] tcp: Remove mmap_lock fallback path From: Suren Baghdasaryan To: akpm@linux-foundation.org Cc: dave.hansen@linux.intel.com, Liam.Howlett@oracle.com, ljs@kernel.org, david@kernel.org, willy@infradead.org, shakeel.butt@linux.dev, vbabka@kernel.org, jannh@google.com, aliceryhl@google.com, arve@android.com, cmllamas@google.com, christian@brauner.io, tkjos@android.com, dsahern@kernel.org, davem@davemloft.net, gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, netdev@vger.kernel.org, surenb@google.com, syzbot@syzkaller.appspotmail.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Dave Hansen Previously, the per-VMA locking could fail in the face of writers which necessitates a fallback to mmap_lock. The new lock_vma_under_rcu_wait() will wait for writers instead of failing. Use the new helper. Wait for writers. Remove the fallback to mmap_lock. The fallback removal does not affect NOMMU case because TCP_ZEROCOPY is gated on CONFIG_MMU. This really is a nice cleanup. It removes the need to pass the lock state back and forth to find_tcp_vma(). Signed-off-by: Dave Hansen Signed-off-by: Suren Baghdasaryan Acked-by: Lorenzo Stoakes Acked-by: Vlastimil Babka (SUSE) Tested-by: syzbot@syzkaller.appspotmail.com Cc: Andrew Morton Cc: Liam R. Howlett Cc: Vlastimil Babka Cc: Shakeel Butt Cc: linux-mm@kvack.org Cc: Greg Kroah-Hartman Cc: Arve Hj=C3=B8nnev=C3=A5g Cc: Todd Kjos Cc: Christian Brauner Cc: Carlos Llamas Cc: Alice Ryhl Cc: David S. Miller Cc: David Ahern Cc: netdev@vger.kernel.org --- net/ipv4/tcp.c | 31 +++++++++---------------------- 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index 455441f1b694..62defe70f3ce 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -2167,27 +2167,18 @@ static void tcp_zc_finalize_rx_tstamp(struct sock *= sk, } =20 static struct vm_area_struct *find_tcp_vma(struct mm_struct *mm, - unsigned long address, - bool *mmap_locked) + unsigned long address) { - struct vm_area_struct *vma =3D lock_vma_under_rcu(mm, address); + struct vm_area_struct *vma =3D vma_start_read_unlocked(mm, address); =20 - if (vma) { - if (vma->vm_ops !=3D &tcp_vm_ops) { - vma_end_read(vma); - return NULL; - } - *mmap_locked =3D false; - return vma; - } + if (!vma) + return NULL; =20 - mmap_read_lock(mm); - vma =3D vma_lookup(mm, address); - if (!vma || vma->vm_ops !=3D &tcp_vm_ops) { - mmap_read_unlock(mm); + if (vma->vm_ops !=3D &tcp_vm_ops) { + vma_end_read(vma); return NULL; } - *mmap_locked =3D true; + return vma; } =20 @@ -2208,7 +2199,6 @@ static int tcp_zerocopy_receive(struct sock *sk, u32 seq =3D tp->copied_seq; u32 total_bytes_to_map; int inq =3D tcp_inq(sk); - bool mmap_locked; int ret; =20 zc->copybuf_len =3D 0; @@ -2233,7 +2223,7 @@ static int tcp_zerocopy_receive(struct sock *sk, return 0; } =20 - vma =3D find_tcp_vma(current->mm, address, &mmap_locked); + vma =3D find_tcp_vma(current->mm, address); if (!vma) return -EINVAL; =20 @@ -2315,10 +2305,7 @@ static int tcp_zerocopy_receive(struct sock *sk, zc, total_bytes_to_map); } out: - if (mmap_locked) - mmap_read_unlock(current->mm); - else - vma_end_read(vma); + vma_end_read(vma); /* Try to copy straggler data. */ if (!ret) copylen =3D tcp_zc_handle_leftover(zc, sk, skb, &seq, copybuf_len, tss); --=20 2.55.0.654.g21b8a5bc05-goog