From: "David Hildenbrand (Arm)" <david@kernel.org>
To: Konstantin Khorenko <khorenko@virtuozzo.com>,
Andrew Morton <akpm@linux-foundation.org>,
Zi Yan <ziy@nvidia.com>,
Baolin Wang <baolin.wang@linux.alibaba.com>,
"Liam R. Howlett" <liam@infradead.org>,
Nico Pache <nico.pache@linux.dev>,
Ryan Roberts <ryan.roberts@arm.com>, Dev Jain <dev.jain@arm.com>,
Barry Song <baohua@kernel.org>, Lance Yang <lance.yang@linux.dev>,
Usama Arif <usama.arif@linux.dev>,
Kiryl Shutsemau <kas@kernel.org>, Peter Xu <peterx@redhat.com>
Cc: "Alex Williamson" <alex@shazbot.org>,
kvm@vger.kernel.org,
"Loïc Molinari" <loic.molinari@collabora.com>,
dri-devel@lists.freedesktop.org,
"Madhavan Srinivasan" <maddy@linux.ibm.com>,
"Ritesh Harjani (IBM)" <ritesh.list@gmail.com>,
linuxppc-dev@lists.ozlabs.org, linux-mm@kvack.org,
linux-kernel@vger.kernel.org, "Jason Gunthorpe" <jgg@ziepe.ca>,
Sashiko <sashiko-bot@kernel.org>,
stable@vger.kernel.org
Subject: Re: [PATCH v3 2/2] mm/huge_memory: deposit a page table for a special PMD copied by fork
Date: Thu, 15 Oct 2026 16:15:33 +0200 [thread overview]
Message-ID: <79b299ac-a588-43e1-af46-e69d8b3e7aca@kernel.org> (raw)
In-Reply-To: <20261014-b4-prep-vstor-149847-copy_huge_pmd-recheck-special-pmd-v3-2-85eaec8417f6@virtuozzo.com>
On 10/14/26 17:46, Konstantin Khorenko wrote:
> Where arch_needs_pgtable_deposit() is true, every huge PMD needs a
> deposited page table. ppc64 in hash mode keeps the hash slot array of
> the huge page in it, so vmf_insert_pfn_pmd() deposits one for each
> special PMD it maps.
>
> copy_huge_pmd() copies a special PMD into the child without a table.
> The child then dereferences a NULL table:
>
> - on the first hash fault on the PMD, in __hash_page_thp();
> - on the zap at munmap() or exit, in hash__pmdp_huge_get_and_clear().
>
> Allocate a table before taking the page table locks and deposit it
> with the copy, as insert_pmd() does.
>
> Fixes: d1503aa9ab805 ("powerpc/64s: Add support for huge pfnmaps")
> Reported-by: Sashiko <sashiko-bot@kernel.org>
> Closes: https://sashiko.dev/#/patchset/20261014-b4-prep-vstor-149847-copy_huge_pmd-recheck-special-pmd-v1-1-d225c60bc316@virtuozzo.com?part=1
> Cc: stable@vger.kernel.org
> Assisted-by: LLM
> Signed-off-by: Konstantin Khorenko <khorenko@virtuozzo.com>
> ---
> mm/huge_memory.c | 11 +++++++++++
> 1 file changed, 11 insertions(+)
>
> diff --git a/mm/huge_memory.c b/mm/huge_memory.c
> index bf788bb231691..2380e4e877f82 100644
> --- a/mm/huge_memory.c
> +++ b/mm/huge_memory.c
> @@ -1961,6 +1961,11 @@ int copy_huge_pmd(struct mm_struct *dst_mm, struct mm_struct *src_mm,
> pmd = pmdp_get_lockless(src_pmd);
> if (unlikely(pmd_present(pmd) && pmd_special(pmd) &&
> !is_huge_zero_pmd(pmd))) {
> + if (arch_needs_pgtable_deposit()) {
> + pgtable = pte_alloc_one(dst_mm);
> + if (unlikely(!pgtable))
> + goto out;
> + }
> dst_ptl = pmd_lock(dst_mm, dst_pmd);
> src_ptl = pmd_lockptr(src_mm, src_pmd);
> spin_lock_nested(src_ptl, SINGLE_DEPTH_NESTING);
> @@ -1974,6 +1979,8 @@ int copy_huge_pmd(struct mm_struct *dst_mm, struct mm_struct *src_mm,
> if (unlikely(pmd_none(pmd))) {
> spin_unlock(src_ptl);
> spin_unlock(dst_ptl);
> + if (pgtable)
> + pte_free(dst_mm, pgtable);
> return -EAGAIN;
> }
> /*
> @@ -1983,6 +1990,10 @@ int copy_huge_pmd(struct mm_struct *dst_mm, struct mm_struct *src_mm,
> * wrongly write to the backend MMIO.
> */
> VM_WARN_ON_ONCE(vma_is_cow_mapping(src_vma) && pmd_write(pmd));
> + if (pgtable) {
> + mm_inc_nr_ptes(dst_mm);
> + pgtable_trans_huge_deposit(dst_mm, dst_pmd, pgtable);
> + }
> goto set_pmd;
It's another sign that the pmd_special() is just entirely misplaced.
Let's get that sorted and it will just naturally fix the other case.
--
Cheers,
David
next prev parent reply other threads:[~2026-10-15 15:48 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-14 15:46 [PATCH v3 0/2] mm/huge_memory: fix the copy of special PMDs at fork Konstantin Khorenko
2026-10-14 15:46 ` [PATCH v3 1/2] mm/huge_memory: recheck a special PMD under the lock in copy_huge_pmd() Konstantin Khorenko
2026-10-15 14:14 ` David Hildenbrand (Arm)
2026-10-14 15:46 ` [PATCH v3 2/2] mm/huge_memory: deposit a page table for a special PMD copied by fork Konstantin Khorenko
2026-10-15 14:15 ` David Hildenbrand (Arm) [this message]
2026-10-14 15:57 ` [PATCH v3 0/2] mm/huge_memory: fix the copy of special PMDs at fork Zi Yan
2026-10-14 16:04 ` Lance Yang
2026-10-15 11:49 ` Konstantin Khorenko
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=79b299ac-a588-43e1-af46-e69d8b3e7aca@kernel.org \
--to=david@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=alex@shazbot.org \
--cc=baohua@kernel.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=dev.jain@arm.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=jgg@ziepe.ca \
--cc=kas@kernel.org \
--cc=khorenko@virtuozzo.com \
--cc=kvm@vger.kernel.org \
--cc=lance.yang@linux.dev \
--cc=liam@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=loic.molinari@collabora.com \
--cc=maddy@linux.ibm.com \
--cc=nico.pache@linux.dev \
--cc=peterx@redhat.com \
--cc=ritesh.list@gmail.com \
--cc=ryan.roberts@arm.com \
--cc=sashiko-bot@kernel.org \
--cc=stable@vger.kernel.org \
--cc=usama.arif@linux.dev \
--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