From: sashiko-bot@kernel.org
To: tao <tao.wangtao@honor.com>
Cc: damon@lists.linux.dev
Subject: Re: [RFC PATCH v2 07/13] mm: handle rmap_base changes for ANON_VMA_FRACTAL
Date: Tue, 07 Jul 2026 08:45:17 +0000 [thread overview]
Message-ID: <20260707084518.72EDF1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260707063308.29176-8-tao.wangtao@honor.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Self-deadlock in VMA modification paths due to recursive acquisition of the anon_vma rw_semaphore, followed by unbalanced unlock leading to semaphore corruption.
--
--- Patch [7]: [RFC PATCH v2 07/13] mm: handle rmap_base changes for ANON_VMA_FRACTAL ---
commit 4ece2a0d48ed77392c6b5765afc8e465e5eeb821
Author: tao <tao.wangtao@honor.com>
mm: handle rmap_base changes for ANON_VMA_FRACTAL
This patch introduces vma_pre_update_rmap_base() and
vma_post_update_rmap_base() to track rmap_base changes during VMA merges
and shrinks. It calls these helpers before vma_prepare() and after
vma_complete() in paths where the rmap_base may change.
> diff --git a/mm/vma.c b/mm/vma.c
> index 9eea2850818a8..d2996369e30d6 100644
> --- a/mm/vma.c
> +++ b/mm/vma.c
[ ... ]
> @@ -748,12 +749,16 @@ static int commit_merge(struct vma_merge_struct *vmg)
> /*
> * If vmg->give_up_on_oom is set, we're safe, because we don't actually
> * manipulate any VMAs until we succeed at preallocation.
> */
> if (vma_iter_prealloc(vmg->vmi, vma))
> return -ENOMEM;
>
> + rbase_diff = rmap_base(vmg->start, vmg->pgoff) - vma_rmap_base(vma);
> + if (rbase_diff && vma_pre_update_rmap_base(vma, rbase_diff)) {
> + vma_iter_free(vmg->vmi);
> + return -ENOMEM;
> + }
> +
> vma_prepare(&vp);
[Severity: High]
Will this sequence cause a self-deadlock on the anon_vma rw_semaphore?
Looking at vma_pre_update_rmap_base(), it acquires the write lock on the
semaphore via down_write(anon_node_rmap_sem(anon_nod)).
Immediately after that, vma_prepare() is called here. Since vma_prepare()
unconditionally calls anon_vma_lock_write() which attempts to acquire the
exact same rw_semaphore, won't the second down_write() block indefinitely
because Linux rw_semaphores are not recursive for writers?
The exact same pattern is also present in vma_shrink().
> diff --git a/mm/rmap.c b/mm/rmap.c
> index 900a9d9e5e6a3..2a31f0441c114 100644
> --- a/mm/rmap.c
> +++ b/mm/rmap.c
[ ... ]
> +void vma_post_update_rmap_base(struct vm_area_struct *vma, unsigned long diff)
> +{
> + struct anon_node *anon_nod = vma_anon_node(vma);
> + struct rw_semaphore *rmap_sem;
> + struct anon_node *release_node = NULL;
> +
> + vma_assert_write_locked(vma);
> + if (!anon_nod || !diff)
> + return;
> +
> + rmap_sem = anon_node_rmap_sem(anon_nod);
> + rwsem_assert_held_write(rmap_sem);
> + anon_node_untrack_rmap_locked(anon_nod, vma,
> + vma_rmap_base(vma) - diff, &release_node);
> + up_write(rmap_sem);
[Severity: High]
Does this up_write() corrupt the semaphore state?
This function is called in commit_merge() and vma_shrink() right after
vma_complete(). Because vma_complete() releases the locks previously
acquired by vma_prepare(), the rw_semaphore has already been unlocked by the
time we reach this code.
Will calling up_write() on an already-unlocked semaphore cause kernel
instability or further lock corruption?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260707063308.29176-1-tao.wangtao@honor.com?part=7
next prev parent reply other threads:[~2026-07-07 8:45 UTC|newest]
Thread overview: 41+ 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 [this message]
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
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-08 4:37 ` Hillf Danton
2026-07-08 7:45 ` David Hildenbrand (Arm)
2026-07-08 9:15 ` Hillf Danton
2026-07-08 11:05 ` David Hildenbrand (Arm)
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=20260707084518.72EDF1F000E9@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.