DAMON development mailing list
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: tao <tao.wangtao@honor.com>
Cc: damon@lists.linux.dev
Subject: Re: [RFC PATCH v2 10/13] mm: replace anon_vma with anon_node for ANON_VMA_FRACTAL
Date: Tue, 07 Jul 2026 09:25:22 +0000	[thread overview]
Message-ID: <20260707092523.419FD1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260707063308.29176-11-tao.wangtao@honor.com>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [Critical] Desynchronization of `prev` and `tmp_prev` pointers in `dup_mmap()` leads to `anon_node` tree corruption when VMAs are skipped, causing page use-after-free and structural corruption.
- [Critical] The `ANON_RMAP_FOREACH_VMA` macro enters an infinite loop when callers use a `continue` statement, leading to a hard lockup.
- [High] Stubbing `anon_vma_lock_write` to a no-op breaks locking in `mremap` and `khugepaged`, leading to concurrent page table corruption.
--

--- Patch [10]: [RFC PATCH v2 10/13] mm: replace anon_vma with anon_node for ANON_VMA_FRACTAL ---
commit 1deef9c4b5a4ec2adb2fbed6a3ce6762667d351c
Author: tao <tao.wangtao@honor.com>
Subject: mm: replace anon_vma with anon_node for ANON_VMA_FRACTAL

This commit replaces anon_vma with anon_node for anonymous reverse mapping
walks, aiming to save memory by removing anon_vma_chain from VMA. It
introduces a new ANON_RMAP_FOREACH_VMA macro and stubs out older locking
APIs.

> diff --git a/mm/internal.h b/mm/internal.h
> index 1c29f98b1b252..7c34ff1abf85c 100644
> --- a/mm/internal.h
> +++ b/mm/internal.h
[ ... ]
> +/* Huge pages are protected by folio_lock(), these APIs no longer needed. */
> +static inline void anon_vma_lock_write(struct anon_vma *anon_vma) {}
> +static inline int anon_vma_trylock_write(struct anon_vma *anon_vma) { return 1; }
> +static inline void anon_vma_unlock_write(struct anon_vma *anon_vma) {}

[Severity: High]
Does stubbing out anon_vma_lock_write() leave page table modifications
unprotected against concurrent reverse mapping accesses?

Operations like take_rmap_locks() in mm/mremap.c and collapse_huge_page()
in mm/khugepaged.c still rely on this lock to serialize page table changes.
Without it, there could be page table corruption when try_to_unmap()
locklessly scans them.

> diff --git a/mm/mmap.c b/mm/mmap.c
> index 2311ae7c2ff45..c283e0de819af 100644
> --- a/mm/mmap.c
> +++ b/mm/mmap.c
[ ... ]
>  	mt_clear_in_rcu(vmi.mas.tree);
> -	for_each_vma(vmi, mpnt) {
> +	for ( ; (mpnt = vma_next(&vmi)) != NULL; prev = mpnt, tmp_prev = tmp) {
>  		struct file *file;

[Severity: Critical]
Does this loop advancement logic cause prev and tmp_prev to become
desynchronized if a VMA is skipped?

If mpnt->vm_flags & VM_DONTCOPY is true, the loop in dup_mmap() executes a
continue statement. The step expression will update prev to mpnt (the skipped
VMA), but tmp_prev will remain pointing to the clone of an unrelated older
VMA.

[ ... ]
>  			tmp->anon_vma = NULL;
> -		} else if (anon_vma_fork(tmp, mpnt))
> +		} else if (anon_vma_fork_with_prev(tmp, mpnt, tmp_prev, prev))
>  			goto fail_nomem_anon_vma_fork;

[Severity: Critical]
If prev and tmp_prev are desynchronized due to a prior skipped VMA, will
this cause anon_vma_fork_with_prev() to incorrectly reuse an anon_node from
an unrelated mapping?

This could place child VMAs in the wrong reverse mapping tree, leading to
use-after-free regressions when the kernel attempts to unmap or swap out
pages.

> diff --git a/mm/rmap.c b/mm/rmap.c
> index aa6632790d9af..d3677515fae92 100644
> --- a/mm/rmap.c
> +++ b/mm/rmap.c
[ ... ]
> @@ -3455,9 +3460,7 @@ static void rmap_walk_anon(struct folio *folio,
>  
>  	pgoff_start = folio_pgoff(folio);
>  	pgoff_end = pgoff_start + folio_nr_pages(folio) - 1;
> -	anon_vma_interval_tree_foreach(avc, &anon_vma->rb_root,
> -			pgoff_start, pgoff_end) {
> -		struct vm_area_struct *vma = avc->vma;
> +	ANON_RMAP_FOREACH_VMA(anon_vma, 0, pgoff_start, pgoff_end, ({
>  		unsigned long address = vma_address(vma, pgoff_start,
>  				folio_nr_pages(folio));
>  

[Severity: Critical]
Can the use of continue inside this macro block bypass the iterator
advancement logic of ANON_RMAP_FOREACH_VMA?

When CONFIG_ANON_VMA_FRACTAL is enabled, ANON_RMAP_FOREACH_VMA is defined
as a while loop that advances the iterator at the end of the block. If a
caller like rmap_walk_anon() jumps to the next iteration using continue,
it will skip the advancement and result in an infinite loop and softlockup.

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

  reply	other threads:[~2026-07-07  9:25 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-07  6:32 [RFC PATCH v2 00/13] mm: rework anon_vma and remove anon_vma_chain tao
2026-07-07  6:32 ` [RFC PATCH v2 01/13] mm: add CONFIG_ANON_VMA_FRACTAL tao
2026-07-07  7:11   ` sashiko-bot
2026-07-07  6:32 ` [RFC PATCH v2 02/13] mm: implement helpers for ANON_VMA_FRACTAL tao
2026-07-07  7:23   ` sashiko-bot
2026-07-07  6:32 ` [RFC PATCH v2 03/13] mm: implement __anon_node_prepare " tao
2026-07-07  7:39   ` sashiko-bot
2026-07-07  6:32 ` [RFC PATCH v2 04/13] mm: implement anon_node_clone " tao
2026-07-07  8:00   ` sashiko-bot
2026-07-07  6:33 ` [RFC PATCH v2 05/13] mm: implement anon_node_fork_with_prev " tao
2026-07-07  8:22   ` sashiko-bot
2026-07-07  6:33 ` [RFC PATCH v2 06/13] mm: implement unlink_anon_nodes " tao
2026-07-07  6:33 ` [RFC PATCH v2 07/13] mm: handle rmap_base changes " tao
2026-07-07  8:45   ` sashiko-bot
2026-07-07  6:33 ` [RFC PATCH v2 08/13] mm: implement anonymous folio rmap " tao
2026-07-07  9:01   ` sashiko-bot
2026-07-07  6:33 ` [RFC PATCH v2 09/13] mm: prepare anon_node replacement " tao
2026-07-07  9:12   ` sashiko-bot
2026-07-07  6:33 ` [RFC PATCH v2 10/13] mm: replace anon_vma with anon_node " tao
2026-07-07  9:25   ` sashiko-bot [this message]
2026-07-07  6:33 ` [RFC PATCH v2 11/13] mm: optimize rmap for ANON_VMA_FRACTAL with PVL tao
2026-07-07  9:41   ` sashiko-bot
2026-07-07  6:33 ` [RFC PATCH v2 12/13] mm: shared semaphores for ANON_VMA_FRACTAL tao
2026-07-07  9:59   ` sashiko-bot
2026-07-07  6:33 ` [RFC PATCH v2 13/13] mm: Enable CONFIG_ANON_VMA_FRACTAL by default tao
2026-07-07 10:21   ` sashiko-bot
2026-07-07  7:01 ` [RFC PATCH v2 00/13] mm: rework anon_vma and remove anon_vma_chain David Hildenbrand (Arm)
2026-07-07  8:21   ` wangtao
2026-07-07  8:31     ` David Hildenbrand (Arm)
2026-07-07  9:20       ` wangtao
2026-07-07 16:19         ` Gregory Price
2026-07-07 17:09         ` David Hildenbrand (Arm)
2026-07-08  3:26           ` wangtao
2026-07-08  8:18             ` David Hildenbrand (Arm)
2026-07-07  9:07     ` Pedro Falcato
2026-07-07 15:27 ` Borislav Petkov
2026-07-07 21:32 ` [syzbot ci] " syzbot ci

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=20260707092523.419FD1F000E9@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox