Thread (22 messages) 22 messages, 6 authors, 2025-09-24

Re: [PATCH 1/1] mm/thp: fix MTE tag mismatch when replacing zero-filled subpages

From: Catalin Marinas <catalin.marinas@arm.com>
Date: 2025-09-24 10:02:13
Also in: linux-mediatek, linux-mm, lkml, stable

On Wed, Sep 24, 2025 at 11:44:19AM +0200, David Hildenbrand wrote:
On 24.09.25 11:34, Catalin Marinas wrote:
quoted
On Wed, Sep 24, 2025 at 11:13:18AM +0200, David Hildenbrand wrote:
quoted
On 24.09.25 10:50, Catalin Marinas wrote:
quoted
On Wed, Sep 24, 2025 at 10:49:27AM +0800, Lance Yang wrote:
quoted
On 2025/9/24 00:14, Catalin Marinas wrote:
quoted
So alternative patch that also fixes the deferred struct page init (on
the assumptions that the zero page is always mapped as pte_special():
I can confirm that this alternative patch also works correctly; my tests
for MTE all pass ;)
Thanks Lance for testing. I'll post one of the variants today.
quoted
This looks like a better fix since it solves the boot hang issue too.
In principle, yes, until I tracked down why I changed it in the first
place - 68d54ceeec0e ("arm64: mte: Allow PTRACE_PEEKMTETAGS access to
the zero page"). ptrace() can read tags from PROT_MTE mappings and we
want to allow reading zeroes as well if the page points to the zero
page. Not flagging the page as PG_mte_tagged caused issues.

I can change the logic in the ptrace() code, I just need to figure out
what happens to the huge zero page. Ideally we should treat both in the
same way but, AFAICT, we don't use pmd_mkspecial() on the huge zero
page, so it gets flagged with PG_mte_tagged.
I changed that recently :) The huge zero folio will now always have
pmd_special() set.
Oh, which commit was this? It means that we can end up with
uninitialised tags if we have a PROT_MTE huge zero page since
set_pmd_at/set_pte_at() skips mte_sync_tags().
This one:

commit d82d09e482199e6bbc204df10b2082f764cbe1f4
Author: David Hildenbrand [off-list ref]
Date:   Mon Aug 11 13:26:25 2025 +0200

    mm/huge_memory: mark PMD mappings of the huge zero folio special

    The huge zero folio is refcounted (+mapcounted -- is that a word?)
    differently than "normal" folios, similarly (but different) to the
    ordinary shared zeropage.


It should be in mm-stable, to go upstream in the upcoming merge window. It's
been lurking in -next for a while now.
Thanks. At least it's something to address in the next kernel version. I
need to improve the MTE kselftests to catch the zero page scenarios.
As it behaves just like the ordinary shared zeropage now, would we have to
zero/initialize the tags after allocating it?
Yes. Before pmd_special(), it was be done lazily via set_pmd_at(). I
think it just needs a __GFP_ZEROTAGS. The only other place we use this
flag is in vma_alloc_zeroed_movable_folio(), as an optimisation to avoid
a separate loop for zeroing the tags after data.

-- 
Catalin
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help