All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: tao <tao.wangtao@honor.com>
Cc: damon@lists.linux.dev
Subject: Re: [PATCH 15/15] mm: enable CONFIG_ANON_VMA_LAZY on arm64 and x86_64
Date: Wed, 27 May 2026 17:19:53 +0000	[thread overview]
Message-ID: <20260527171954.511651F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260527110147.17815-16-tao.wangtao@honor.com>

Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:

Pre-existing issues:
- [Critical] Dereferencing mm_struct in folio_resolve_anon_vma_lazy() causes a use-after-free because SLAB_TYPESAFE_BY_RCU allows the VMA to be recycled without pinning the new mm_struct.
- [Critical] Unbalanced refcount drop in vma_prepare_anon_vma() error path causes an underflow and premature freeing of the root anon_vma.
- [High] Toggling the sysctl anon_vma_lazy at runtime causes Use-After-Free and VM_BUG_ON_VMA crashes due to flawed structural state checks.
- [High] Unmapping the root of a split lazy anon VMA clears its anon_vma pointer, permanently breaking reverse mapping for folios in the remaining child VMAs.
--

commit 6ca138075f0d0c3a8eba3846297fc8cdfbebaa40
Author: tao <tao.wangtao@honor.com>

mm: enable CONFIG_ANON_VMA_LAZY on arm64 and x86_64

All prerequisites are in place, so enable CONFIG_ANON_VMA_LAZY for
arm64 and x86_64.

> diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
> index fe60738e5943b..9517883f0aaf2 100644
> --- a/arch/arm64/Kconfig
> +++ b/arch/arm64/Kconfig
[ ... ]
> @@ -81,6 +81,7 @@ config ARM64
>  	select ARCH_SUPPORTS_NUMA_BALANCING
>  	select ARCH_SUPPORTS_PAGE_TABLE_CHECK
>  	select ARCH_SUPPORTS_PER_VMA_LOCK
> +	select ARCH_SUPPORTS_ANON_VMA_LAZY
>  	select ARCH_SUPPORTS_HUGE_PFNMAP if TRANSPARENT_HUGEPAGE
>  	select ARCH_SUPPORTS_RT
>  	select ARCH_SUPPORTS_SCHED_SMT
> diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
> index f3f7cb01d69d0..cc3430eaa7b41 100644
> --- a/arch/x86/Kconfig
> +++ b/arch/x86/Kconfig
[ ... ]
> @@ -28,6 +28,7 @@ config X86_64
>  	select ARCH_SUPPORTS_MSEAL_SYSTEM_MAPPINGS
>  	select ARCH_SUPPORTS_INT128 if CC_HAS_INT128
>  	select ARCH_SUPPORTS_PER_VMA_LOCK
> +	select ARCH_SUPPORTS_ANON_VMA_LAZY
>  	select ARCH_SUPPORTS_HUGE_PFNMAP if TRANSPARENT_HUGEPAGE
>  	select HAVE_ARCH_SOFT_DIRTY
>  	select MODULES_USE_ELF_RELA
> diff --git a/mm/rmap.c b/mm/rmap.c
> index b3bebb58e3597..4edf3311b1ae0 100644
> --- a/mm/rmap.c
> +++ b/mm/rmap.c
[ ... ]
> @@ -168,7 +168,7 @@ static struct kmem_cache *anon_vma_chain_cachep;
>   *        covering both regular anon_vma and lazy anon_vma mappings.
>   */
>  
> -bool anon_vma_lazy_enable;
> +bool anon_vma_lazy_enable = true;

[Severity: Critical]
This is a pre-existing issue, but enabling this by default exposes a potential
use-after-free when dereferencing the mm_struct in
folio_resolve_anon_vma_lazy().

During an RCU reverse mapping walk, folio_resolve_anon_vma_lazy() reads
mm = vma->vm_mm locklessly. Because VMAs are allocated with
SLAB_TYPESAFE_BY_RCU, the vma can be recycled and reallocated to a different
process during the walk.

The function calls vma_get() to increment the VMA refcount, but fails to pin
the foreign mm_struct via mmgrab(). If the foreign process exits concurrently,
its mm_struct is freed. The subsequent vma_lookup(mm, addr) dereferences
mm->mm_mt, resulting in a use-after-free.

Should the foreign mm_struct be stabilized with mmgrab() before performing
the lookup?

[Severity: Critical]
This is a pre-existing issue, but enabling this by default exposes an
unbalanced refcount drop in the vma_prepare_anon_vma() error path.

When attempting to upgrade a lazy anon_vma, a new anon_vma may be allocated.
If this thread loses a race and the VMA is already upgraded by another thread,
the likely(!vma->anon_vma || is_lazy) check evaluates to false, skipping
get_anon_vma(anon_vma->root).

However, the cleanup path unconditionally calls put_anon_vma(allocated).
Inside __put_anon_vma(), the root's refcount is decremented. Since it was
never incremented by this thread, this causes a refcount underflow and
premature freeing of the root anon_vma. This can lead to a use-after-free
for all other VMAs mapped to it.

Could the cleanup path be adjusted to only decrement the refcount if it was
successfully incremented?

[Severity: High]
This is a pre-existing issue, but enabling this by default exposes crashes
and memory issues if anon_vma_lazy_enable is toggled at runtime.

Disabling anon_vma_lazy_enabled() at runtime causes structural inconsistencies
for existing lazy VMAs. In anon_vma_fork(), the lazy fork path is skipped,
falling through to anon_vma_clone(), which calls vma_link_anon_vma_lazy_root().
This triggers VM_BUG_ON_VMA(vma->vm_mm != src->vm_mm, vma), which will crash
the kernel.

Furthermore, SWAP_VMG_TARGET_IF_DELETE_ANON_VMA_LAZY_ROOT() becomes a no-op,
meaning a pre-existing lazy root VMA being merged is deleted instead of
preserved. Reverse mapping walkers will later dereference this freed VMA via
folio->mapping, leading to a use-after-free.

Is it safe to toggle this sysctl at runtime while lazy VMAs already exist in
the system?

[Severity: High]
This is a pre-existing issue, but enabling this by default exposes a
regression when unmapping the root of a split lazy anon VMA.

When a lazy anon VMA is split, anon_vma_clone() links the new child VMA to
the root VMA by holding a reference to the root. If the root VMA is later
unmapped, unlink_anon_vmas() clears root_vma->anon_vma = NULL.

However, the child VMA remains alive, and its anonymous folios still point to
the root VMA via folio->mapping. During a reverse mapping walk,
folio_resolve_anon_vma_lazy() discovers !vma->anon_vma and aborts early.

This permanently breaks reverse mapping for the folios in the child VMA,
preventing them from being unmapped, migrated, or swapped out.

Does clearing root_vma->anon_vma need to account for surviving child VMAs to
avoid breaking reverse mapping?

>  #endif
>  
>  static inline struct anon_vma *anon_vma_alloc(void)

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260527110147.17815-1-tao.wangtao@honor.com?part=15

  reply	other threads:[~2026-05-27 17:19 UTC|newest]

Thread overview: 82+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-27 11:01 [PATCH 0/15] mm: introduce ANON_VMA_LAZY for deferred anon_vma creation tao
2026-05-27 11:01 ` [PATCH 01/15] mm/rmap: introduce anon_rmap APIs for anonymous folios tao
2026-05-27 11:32   ` sashiko-bot
2026-05-27 11:44   ` Lorenzo Stoakes
2026-05-28  7:47     ` wangtao
2026-05-27 11:01 ` [PATCH 02/15] mm: convert anon_vma rmap APIs to anon_rmap tao
2026-05-27 11:49   ` Lorenzo Stoakes
2026-05-28  8:55     ` wangtao
2026-05-27 11:01 ` [PATCH 03/15] mm: introduce anon_vma_tree_t for multiple anon_vma topologies tao
2026-05-27 11:56   ` Lorenzo Stoakes
2026-05-28  9:00     ` wangtao
2026-05-27 11:01 ` [PATCH 04/15] mm: switch to anon_vma_tree_t APIs in preparation for ANON_VMA_LAZY tao
2026-05-27 11:53   ` sashiko-bot
2026-05-27 11:01 ` [PATCH 05/15] mm: add CONFIG_ANON_VMA_LAZY and folio helpers tao
2026-05-27 11:01 ` [PATCH 06/15] mm: add CONFIG_VMA_REF and VMA helpers tao
2026-05-27 11:42   ` sashiko-bot
2026-05-27 11:01 ` [PATCH 07/15] mm: replace direct FOLIO_MAPPING_ANON usage with helpers tao
2026-05-27 11:43   ` sashiko-bot
2026-05-27 11:01 ` [PATCH 08/15] mm: prepare rmap infrastructure for ANON_VMA_LAZY tao
2026-05-27 14:01   ` sashiko-bot
2026-05-27 11:01 ` [PATCH 09/15] mm: implement ANON_VMA_LAZY rmap semantics tao
2026-05-27 12:15   ` sashiko-bot
2026-05-27 11:01 ` [PATCH 10/15] mm: defer anon_vma creation with ANON_VMA_LAZY tao
2026-05-27 12:29   ` sashiko-bot
2026-05-27 11:01 ` [PATCH 11/15] mm: handle ANON_VMA_LAZY in huge page operations tao
2026-05-27 12:21   ` sashiko-bot
2026-05-27 11:01 ` [PATCH 12/15] mm: handle ANON_VMA_LAZY during migration tao
2026-05-27 12:23   ` sashiko-bot
2026-05-27 11:01 ` [PATCH 13/15] mm: support setup and upgrade of ANON_VMA_LAZY folios tao
2026-05-27 13:02   ` sashiko-bot
2026-05-27 11:01 ` [PATCH 14/15] mm: support merging of ANON_VMA_LAZY VMAs tao
2026-05-27 12:49   ` sashiko-bot
2026-05-27 11:01 ` [PATCH 15/15] mm: enable CONFIG_ANON_VMA_LAZY on arm64 and x86_64 tao
2026-05-27 17:19   ` sashiko-bot [this message]
2026-05-27 11:23 ` [PATCH 0/15] mm: introduce ANON_VMA_LAZY for deferred anon_vma creation Pedro Falcato
2026-05-28  6:45   ` wangtao
2026-05-28  7:14     ` Lorenzo Stoakes
2026-05-27 11:30 ` Lorenzo Stoakes
2026-05-28  7:11   ` wangtao
2026-05-28  7:22     ` Lorenzo Stoakes
2026-05-27 14:33 ` Lorenzo Stoakes
2026-05-28  7:57   ` wangtao
2026-05-28  8:14     ` Lorenzo Stoakes
2026-05-28 23:31       ` Barry Song
2026-05-29  2:20         ` wangzicheng
2026-05-29  6:56           ` Lorenzo Stoakes
2026-05-29  6:45         ` Lorenzo Stoakes
2026-05-29  9:41         ` wangtao
2026-05-29 12:03           ` Lorenzo Stoakes
2026-06-01  1:46             ` wangtao
2026-06-02  2:15               ` Barry Song
2026-06-02  2:46                 ` Lance Yang
2026-06-02 15:37                   ` Lorenzo Stoakes
2026-06-02 19:44                     ` Pedro Falcato
2026-06-02 23:03                     ` Barry Song
2026-06-03  7:07                       ` Lorenzo Stoakes
2026-06-02 19:56                 ` Harry Yoo
2026-06-02 22:27                   ` Barry Song
2026-06-02 20:47             ` Lorenzo Stoakes
2026-05-29 15:07         ` Jonathan Corbet
2026-05-29 15:40           ` Lorenzo Stoakes
2026-05-30 11:28             ` Barry Song
2026-06-02 16:07 ` Harry Yoo
2026-06-03  2:59   ` wangtao
2026-06-03  3:12     ` wangtao
2026-06-03  7:54     ` Lorenzo Stoakes
2026-06-03 11:05       ` wangtao
2026-06-03 11:53         ` Lorenzo Stoakes
2026-06-04  3:50           ` wangtao
2026-06-03 20:25 ` David Hildenbrand (Arm)
2026-06-03 22:14   ` Barry Song
2026-06-04  4:03     ` wangtao
2026-06-04  4:20       ` Barry Song
2026-06-04  7:35         ` wangtao
2026-06-09 15:26           ` Suren Baghdasaryan
2026-06-09 15:49             ` David Hildenbrand (Arm)
2026-06-04  3:10   ` xu.xin16
2026-06-04  4:10     ` wangtao
2026-06-05  9:38     ` David Hildenbrand (Arm)
2026-06-05 10:07       ` Lorenzo Stoakes
2026-06-05 10:56         ` David Hildenbrand (Arm)
2026-06-04  9:40   ` Lorenzo Stoakes

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260527171954.511651F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=damon@lists.linux.dev \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=tao.wangtao@honor.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.