From: Alexander Gordeev <agordeev@linux.ibm.com>
To: Zi Yan <ziy@nvidia.com>
Cc: David Hildenbrand <david@kernel.org>,
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>,
Lorenzo Stoakes <ljs@kernel.org>, Rik van Riel <riel@surriel.com>,
Vlastimil Babka <vbabka@kernel.org>, Harry Yoo <harry@kernel.org>,
Jann Horn <jannh@google.com>, Kyle Zeng <kylebot@openai.com>,
Andrew Morton <akpm@linux-foundation.org>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
Gerald Schaefer <gerald.schaefer@linux.ibm.com>,
Heiko Carstens <hca@linux.ibm.com>,
Vasily Gorbik <gor@linux.ibm.com>,
Christian Borntraeger <borntraeger@linux.ibm.com>,
Sven Schnelle <svens@linux.ibm.com>,
John Hubbard <jhubbard@nvidia.com>, Peter Xu <peterx@redhat.com>,
linux-s390@vger.kernel.org, Jason Gunthorpe <jgg@ziepe.ca>
Subject: Re: [PATCH v2 5/9] s390/mm: always clear _SEGMENT_ENTRY_READ in pmdp_invalidate()
Date: Fri, 4 Dec 2026 13:31:14 +0100 [thread overview]
Message-ID: <b62a9090-a334-46ef-9c85-ca461fe98535-agordeev@linux.ibm.com> (raw)
In-Reply-To: <20261203-anon_vma_uaf_fix-v2-5-3d4c746e8839@nvidia.com>
On Thu, Dec 03, 2026 at 11:17:53PM -0500, Zi Yan wrote:
> pmdp_invalidate() sets _SEGMENT_ENTRY_INVALID, but that bit alone does
> not make the entry pmd_protnone(). Also clear the _SEGMENT_ENTRY_READ
> bit to achieve it, so that GUP-fast can no longer grab a reference on the
> folio mapped by the invalidated pmd.
>
> Code can invalidate a PMD and then based on folio refcount decides
> whether it may drop the mapping. That relies on GUP-fast backing off
> from an invalidated PMD, as it does on x86, arm64, and powerpc.
> For example, lazyfree THP discard is about to use pmdp_invalidate() to
> prevent GUP-fast before dropping a lazyfree folio.
>
> With CONFIG_PAGE_TABLE_CHECK, pmdp_invalidate() already clears
> _SEGMENT_ENTRY_READ, which makes the entry pmd_protnone(), so GUP-fast
> does not follow it. Do that unconditionally. As noted in commit
> 7b4dde5e40ad6 ("s390/pgtable: Add s390 support for page table check"),
> an invalidated PMD that is pmd_protnone() is fine for the remaining
> pmd_protnone() users, which run under the page table lock or are
> lockless walkers that should not follow it anyway.
>
> To: Alexander Gordeev <agordeev@linux.ibm.com>
> To: Gerald Schaefer <gerald.schaefer@linux.ibm.com>
> To: Heiko Carstens <hca@linux.ibm.com>
> To: Vasily Gorbik <gor@linux.ibm.com>
> Cc: Christian Borntraeger <borntraeger@linux.ibm.com>
> Cc: Sven Schnelle <svens@linux.ibm.com>
> Cc: Jason Gunthorpe <jgg@nvidia.com>
> Cc: John Hubbard <jhubbard@nvidia.com>
> Cc: Peter Xu <peterx@redhat.com>
> Cc: linux-s390@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org
> Reviewed-by: Gerald Schaefer <gerald.schaefer@linux.ibm.com>
> Signed-off-by: Zi Yan <ziy@nvidia.com>
> ---
> arch/s390/include/asm/pgtable.h | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/arch/s390/include/asm/pgtable.h b/arch/s390/include/asm/pgtable.h
> index 2d5c2ab06de98..fe1ba746203ab 100644
> --- a/arch/s390/include/asm/pgtable.h
> +++ b/arch/s390/include/asm/pgtable.h
> @@ -1781,10 +1781,14 @@ static inline pmd_t pmdp_invalidate(struct vm_area_struct *vma,
> pmd_t pmd = *pmdp;
>
> VM_WARN_ON_ONCE(!pmd_present(pmd));
> + /*
> + * _SEGMENT_ENTRY_INVALID alone also marks an old (not young) entry,
> + * which lockless walkers like GUP-fast may follow. Clear
> + * _SEGMENT_ENTRY_READ too, so the invalidated entry is pmd_protnone()
> + * and is not followed, and page table check does not count it.
> + */
> pmd = set_pmd_bit(pmd, __pgprot(_SEGMENT_ENTRY_INVALID));
> -#ifdef CONFIG_PAGE_TABLE_CHECK
> pmd = clear_pmd_bit(pmd, __pgprot(_SEGMENT_ENTRY_READ));
> -#endif
> page_table_check_pmd_set(vma->vm_mm, addr, pmdp, pmd);
> pmd = pmdp_xchg_direct(vma->vm_mm, addr, pmdp, pmd);
> return pmd;
Reviewed-by: Alexander Gordeev <agordeev@linux.ibm.com>
next prev parent reply other threads:[~2026-12-04 12:31 UTC|newest]
Thread overview: 22+ 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
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
2026-12-04 4:17 ` [PATCH v2 4/9] LoongArch: mm: don't let GUP-fast follow invalidated THP PMDs Zi Yan
2026-12-04 4:17 ` [PATCH v2 5/9] s390/mm: always clear _SEGMENT_ENTRY_READ in pmdp_invalidate() Zi Yan
2026-12-04 12:31 ` Alexander Gordeev [this message]
2026-12-04 4:17 ` [PATCH v2 6/9] sparc64: mm: fix thp_pte_count accounting around pmdp_invalidate() Zi Yan
2026-12-04 4:17 ` [PATCH v2 7/9] mm/huge_memory: avoid transient none PMDs during lazyfree reclaim Zi Yan
2026-12-04 4:35 ` Liam R. Howlett
2026-12-04 9:38 ` Baolin Wang
2026-12-04 13:23 ` Lorenzo Stoakes (ARM)
2026-12-05 4:35 ` Lance Yang
2026-12-05 5:20 ` Lance Yang
2026-12-04 4:17 ` [PATCH v2 8/9] mm/rmap: re-enable discarding lazyfree THPs at PMD level Zi Yan
2026-12-04 4:37 ` Liam R. Howlett
2026-12-04 9:49 ` Baolin Wang
2026-12-05 5:30 ` Lance Yang
2026-12-04 4:17 ` [PATCH v2 9/9] userfaultfd: avoid transient none PMDs during UFFDIO_MOVE Zi Yan
2026-12-04 12:52 ` Lorenzo Stoakes (ARM)
2026-12-05 5:45 ` Lance Yang
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=b62a9090-a334-46ef-9c85-ca461fe98535-agordeev@linux.ibm.com \
--to=agordeev@linux.ibm.com \
--cc=akpm@linux-foundation.org \
--cc=baohua@kernel.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=borntraeger@linux.ibm.com \
--cc=david@kernel.org \
--cc=dev.jain@arm.com \
--cc=gerald.schaefer@linux.ibm.com \
--cc=gor@linux.ibm.com \
--cc=harry@kernel.org \
--cc=hca@linux.ibm.com \
--cc=jannh@google.com \
--cc=jgg@ziepe.ca \
--cc=jhubbard@nvidia.com \
--cc=kas@kernel.org \
--cc=kylebot@openai.com \
--cc=lance.yang@linux.dev \
--cc=liam@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-s390@vger.kernel.org \
--cc=ljs@kernel.org \
--cc=nico.pache@linux.dev \
--cc=peterx@redhat.com \
--cc=riel@surriel.com \
--cc=ryan.roberts@arm.com \
--cc=svens@linux.ibm.com \
--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
all inboxes | Powered by JetHome®