From: Jiakai Xu <jiakaipeanut@gmail.com>
To: ljs@kernel.org
Cc: Liam.Howlett@oracle.com, akpm@linux-foundation.org,
david@kernel.org, harry.yoo@oracle.com, jannh@google.com,
jiakaipeanut@gmail.com, linux-kernel@vger.kernel.org,
linux-mm@kvack.org, riel@surriel.com, sashal@kernel.org,
vbabka@kernel.org, Jiakai Xu <jiakaiPeanut@gmail.com>
Subject: Re: [PATCH mm-hotfixes] mm/rmap: clear vma->anon_vma on error
Date: Thu, 19 Mar 2026 09:12:29 +0800 [thread overview]
Message-ID: <20260319011229.602-1-jiakaiPeanut@gmail.com> (raw)
In-Reply-To: <20260318122632.63404-1-ljs@kernel.org>
> Commit 542eda1a8329 ("mm/rmap: improve anon_vma_clone(), unlink_anon_vmas()
> comments, add asserts") alters the way errors are handled, but overlooked
> one important aspect of clean up.
>
> When a VMA encounters an error state in anon_vma_clone() (that is, on
> attempted allocation of anon_vma_chain objects), it cleans up partially
> established state in cleanup_partial_anon_vmas(), before returning an
> error.
>
> However, this occurs prior to anon_vma->num_active_vmas being incremented,
> and it also fails to clear the VMA's vma->anon_vma field, which remains in
> place.
>
> This is immediately an inconsistent state, because
> anon_vma->num_active_vmas is supposed to track the number of VMAs whose
> vma->anon_vma field references that anon_vma, and now that count is
> off-by-negative-1 for each VMA for which this error state has occurred.
>
> When VMAs are unlinked from this anon_vma, unlink_anon_vmas() will
> eventually underflow anon_vma->num_active_vmas, which will trigger a
> warning.
>
> This will always eventually happen, as we unlink anon_vma's at process
> teardown.
>
> It could also cause maybe_reuse_anon_vma() to incorrectly permit the reuse
> of an anon_vma which has active VMAs attached, which will lead to a
> persistently invalid state.
>
> The solution is to clear the VMA's anon_vma field when we clean up partial
> state, as the fact we are doing so indicates clearly that the VMA is not
> correctly integrated into the anon_vma tree and thus this field is invalid.
>
> Reported-by: Sasha Levin <sashal@kernel.org>
> Closes: https://lore.kernel.org/linux-mm/20260302151547.2389070-1-sashal@kernel.org/
> Reported-by: Jiakai Xu <jiakaipeanut@gmail.com>
> Closes: https://lore.kernel.org/linux-mm/CAFb8wJvRhatRD-9DVmr5v5pixTMPEr3UKjYBJjCd09OfH55CKg@mail.gmail.com/
> Fixes: 542eda1a8329 ("mm/rmap: improve anon_vma_clone(), unlink_anon_vmas() comments, add asserts")
> Signed-off-by: Lorenzo Stoakes (Oracle) <ljs@kernel.org>
Tested-by: Jiakai Xu <jiakaiPeanut@gmail.com>
Thanks!
> ---
> mm/rmap.c | 7 +++++++
> 1 file changed, 7 insertions(+)
>
> diff --git a/mm/rmap.c b/mm/rmap.c
> index 6398d7eef393..abe4712a220c 100644
> --- a/mm/rmap.c
> +++ b/mm/rmap.c
> @@ -457,6 +457,13 @@ static void cleanup_partial_anon_vmas(struct vm_area_struct *vma)
> list_del(&avc->same_vma);
> anon_vma_chain_free(avc);
> }
> +
> + /*
> + * The anon_vma assigned to this VMA is no longer valid, as we were not
> + * able to correctly clone AVC state. Avoid inconsistent anon_vma tree
> + * state by resetting.
> + */
> + vma->anon_vma = NULL;
> }
>
> /**
> --
> 2.53.0
next prev parent reply other threads:[~2026-03-19 1:12 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-18 12:26 Lorenzo Stoakes (Oracle)
2026-03-18 12:52 ` David Hildenbrand (Arm)
2026-03-18 13:03 ` Lorenzo Stoakes (Oracle)
2026-03-18 13:38 ` David Hildenbrand (Arm)
2026-03-18 14:15 ` Lorenzo Stoakes (Oracle)
2026-03-18 13:29 ` Vlastimil Babka
2026-03-19 1:12 ` Jiakai Xu [this message]
2026-03-19 5:26 ` Harry Yoo
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=20260319011229.602-1-jiakaiPeanut@gmail.com \
--to=jiakaipeanut@gmail.com \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=david@kernel.org \
--cc=harry.yoo@oracle.com \
--cc=jannh@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=riel@surriel.com \
--cc=sashal@kernel.org \
--cc=vbabka@kernel.org \
/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