From: Lance Yang <lance.yang@linux.dev>
To: ziy@nvidia.com
Cc: david@kernel.org, baolin.wang@linux.alibaba.com,
liam@infradead.org, nico.pache@linux.dev, ryan.roberts@arm.com,
dev.jain@arm.com, baohua@kernel.org, lance.yang@linux.dev,
usama.arif@linux.dev, kas@kernel.org, ljs@kernel.org,
riel@surriel.com, vbabka@kernel.org, harry@kernel.org,
jannh@google.com, kylebot@openai.com, akpm@linux-foundation.org,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org, balbirs@nvidia.com, apopple@nvidia.com
Subject: Re: [PATCH v2 1/9] mm/migrate: do not clear device private entry in set_pmd_migration_entry()
Date: Sat, 5 Dec 2026 12:06:42 +0800 [thread overview]
Message-ID: <20261205040642.59485-1-lance.yang@linux.dev> (raw)
In-Reply-To: <20261203-anon_vma_uaf_fix-v2-1-3d4c746e8839@nvidia.com>
On Thu, Dec 03, 2026 at 11:17:49PM -0500, Zi Yan wrote:
>A device private entry is never followed by GUP-fast, so there is no need
>to clear the entry to avoid it. Furthermore, clearing the entry creates a
>none PMD and a concurrent zap skips it. set_pmd_migration_entry() might not
Nit: maybe "a concurrent zap or mremap" here :)
>hold a VMA lock nor a mmap lock. As a result:
>
>1. When racing with munmap(), a "bad pmd" can appear, deposited page table
> can be lost, and RSS stats can be off.
>2. When racing with mremap(), the PMD is not moved, so the new address
> faults and sees zeros instead of the original data.
>
>Fix it by not clearing device private entry.
Right. Going straight to the migration entry without that none PMD in
between:
before: device-private PMD -> none PMD -> migration PMD
after: device-private PMD -------------> migration PMD
And, took a quick look at GUP-fast and folio_try_share_anon_rmap_pmd()
too, and neither cares about keeping the entry around :D
>Fixes: 65edfda6f3f2e ("mm/rmap: extend rmap and migration support device-private entries")
>Cc: stable@vger.kernel.org
>Signed-off-by: Zi Yan <ziy@nvidia.com>
>To: David Hildenbrand <david@kernel.org>
>To: Zi Yan <ziy@nvidia.com>
>To: Andrew Morton <akpm@linux-foundation.org>
>Cc: Baolin Wang <baolin.wang@linux.alibaba.com>
>Cc: "Liam R. Howlett" <liam@infradead.org>
>Cc: Nico Pache <nico.pache@linux.dev>
>Cc: Ryan Roberts <ryan.roberts@arm.com>
>Cc: Dev Jain <dev.jain@arm.com>
>Cc: Barry Song <baohua@kernel.org>
>Cc: Lance Yang <lance.yang@linux.dev>
>Cc: Usama Arif <usama.arif@linux.dev>
>Cc: Kiryl Shutsemau <kas@kernel.org>
>Cc: Balbir Singh <balbirs@nvidia.com>
>Cc: Alistair Popple <apopple@nvidia.com>
>Cc: linux-mm@kvack.org
>Cc: linux-kernel@vger.kernel.org
>---
> mm/huge_memory.c | 7 ++++++-
> 1 file changed, 6 insertions(+), 1 deletion(-)
>
>diff --git a/mm/huge_memory.c b/mm/huge_memory.c
>index 6305b4e2a6b68..91f3c7e7a044a 100644
>--- a/mm/huge_memory.c
>+++ b/mm/huge_memory.c
>@@ -5223,7 +5223,12 @@ int set_pmd_migration_entry(struct page_vma_mapped_walk *pvmw,
> } else {
> softleaf_t old_entry;
>
>- pmdval = pmdp_huge_get_and_clear(vma->vm_mm, address, pvmw->pmd);
>+ /*
>+ * The device private entry stays as is since GUP-fast
>+ * never follows it and folio_try_share_anon_rmap_pmd()
>+ * below never fails for it.
>+ */
>+ pmdval = pmdp_get(pvmw->pmd);
LGTM!
Reviewed-by: Lance Yang <lance.yang@linux.dev>
next prev parent reply other threads:[~2026-12-05 4:06 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 4:17 [PATCH v2 0/9] Re-enable discarding lazyfree PMD THPs and transient none PMD fixes Zi Yan
2026-12-04 4:17 ` [PATCH v2 1/9] mm/migrate: do not clear device private entry in set_pmd_migration_entry() Zi Yan
2026-12-05 4:06 ` Lance Yang [this message]
2026-12-04 4:17 ` [PATCH v2 2/9] powerpc/book3s64/mm: don't count invalidated PMDs in page table check Zi Yan
2026-12-04 4:17 ` [PATCH v2 3/9] riscv: mm: don't let GUP-fast follow entries without _PAGE_READ Zi Yan
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=20261205040642.59485-1-lance.yang@linux.dev \
--to=lance.yang@linux.dev \
--cc=akpm@linux-foundation.org \
--cc=apopple@nvidia.com \
--cc=balbirs@nvidia.com \
--cc=baohua@kernel.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=david@kernel.org \
--cc=dev.jain@arm.com \
--cc=harry@kernel.org \
--cc=jannh@google.com \
--cc=kas@kernel.org \
--cc=kylebot@openai.com \
--cc=liam@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=nico.pache@linux.dev \
--cc=riel@surriel.com \
--cc=ryan.roberts@arm.com \
--cc=stable@vger.kernel.org \
--cc=usama.arif@linux.dev \
--cc=vbabka@kernel.org \
--cc=ziy@nvidia.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