mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "David Hildenbrand (Arm)" <david@kernel.org>
To: Yeoreum Yun <yeoreum.yun@arm.com>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org
Cc: Jason Gunthorpe <jgg@ziepe.ca>,
	John Hubbard <jhubbard@nvidia.com>, Peter Xu <peterx@redhat.com>,
	Lorenzo Stoakes <ljs@kernel.org>,
	"Liam R. Howlett" <liam@infradead.org>,
	Vlastimil Babka <vbabka@kernel.org>,
	Mike Rapoport <rppt@kernel.org>,
	Suren Baghdasaryan <surenb@google.com>,
	Michal Hocko <mhocko@suse.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Rik van Riel <riel@surriel.com>,
	Yuan-Hao Hsu <aa9736195201@gmail.com>,
	stable@vger.kernel.org
Subject: Re: [PATCH v3 1/6] mm: khugepaged: ignore MADV_HUGEPAGE for shadow stacks
Date: Mon, 9 Nov 2026 15:22:45 +0100	[thread overview]
Message-ID: <3a2d4135-f531-4797-8dd2-a2732a846e45@kernel.org> (raw)
In-Reply-To: <20261109-refactor_gup_fast-v3-1-2aaef02df0e1@arm.com>

On 11/9/26 13:32, Yeoreum Yun wrote:
> commit 3efb9800557b ("mm: do not map the shadow stack as THP") makes
> shadow stack mappings default to VM_NOHUGEPAGE. However, userspace can
> still clear this flag and set VM_HUGEPAGE through madvise().
> 
> Allowing large folios in x86 shadow stacks exposes a limitation in
> folio_pte_batch_flags(). For example:
> 
>   1. create a shadow stack mapping.
>   2. apply MADV_HUGEPAGE and populate the mapping with a PTE-mapped
>      large folio.
>   3. apply MADV_DONTFORK to the first base page of that folio.
>   4. call fork().
> 
> In the parent, the first page remains writable and anonymous-exclusive,
> while the remaining pages shared with the child become write-protected
> and lose PageAnonExclusive(). These pages can still belong to the same
> large folio.
> 
> On x86, writable shadow-stack PTEs have _PAGE_RW clear and _PAGE_DIRTY
> set. Write-protected PTEs have both bits clear, with the dirty state
> preserved in _PAGE_SAVED_DIRTY.
> 
> When FPB_RESPECT_WRITE is set without FPB_RESPECT_DIRTY,
> folio_pte_batch_flags() normalizes PTEs using pte_mkclean(), which clears
> both dirty bits. This loses the distinction between writable
> shadow-stack PTEs and write-protected PTEs, allowing them to be grouped
> into the same batch. GUP-fast can encounter such a batch when walking
> across the VMA boundary created by MADV_DONTFORK.
> 
> Since there is no practical use-case shadow stack with large folio,
> ignore MADV_HUGEPAGE for shadow stack mappings, preserving their
> VM_NOHUGEPAGE setting and preventing large-folio allocation.
> 
> Fixes: 3efb9800557b ("mm: do not map the shadow stack as THP")
> Suggested-by: David Hildenbrand (Arm) <david@kernel.org>
> Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com>
> Cc: <stable@vger.kernel.org>
> ---
>  mm/khugepaged.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/mm/khugepaged.c b/mm/khugepaged.c
> index 40fad28c52f6f..51ec043fa26c3 100644
> --- a/mm/khugepaged.c
> +++ b/mm/khugepaged.c
> @@ -367,6 +367,9 @@ int hugepage_madvise(struct vm_area_struct *vma,
>  {
>  	switch (advice) {
>  	case MADV_HUGEPAGE:
> +		/* PTE batching doesn't work reliably. */
> +		if (vma_test_single_mask(vma, VMA_SHADOW_STACK))
> +			break;
>  		*vm_flags &= ~VM_NOHUGEPAGE;
>  		*vm_flags |= VM_HUGEPAGE;
>  		break;
> 

Ack, I prefer this solution for now until we know how to make pte_mkclean() on
x86 shadow stack PTEs not result in an implicit pte_wrprotect().

Acked-by: David Hildenbrand (Arm) <david@kernel.org>

-- 
Cheers,

David

  reply	other threads:[~2026-11-09 14:22 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-09 12:32 [PATCH v3 0/6] mm: gup: batch PTE-mapped large folios in gup_fast_pte_range() Yeoreum Yun
2026-11-09 12:32 ` [PATCH v3 1/6] mm: khugepaged: ignore MADV_HUGEPAGE for shadow stacks Yeoreum Yun
2026-11-09 14:22   ` David Hildenbrand (Arm) [this message]
2026-11-09 12:32 ` [PATCH v3 2/6] mm: gup: clarify a reason to check pte/pmd in gup_fast_pte_range() Yeoreum Yun
2026-11-09 12:32 ` [PATCH v3 3/6] mm: gup: move gup_must_unshare() and INTERNAL_GUP_FLAGS to gup.c Yeoreum Yun
2026-11-09 12:32 ` [PATCH v3 4/6] mm: internal: introduce FPB_LOCKLESS for folio_pte_batch_flags() Yeoreum Yun
2026-11-09 12:32 ` [PATCH v3 5/6] mm: gup: introduce gup_unshared_pages() Yeoreum Yun
2026-11-09 12:32 ` [PATCH v3 6/6] mm: gup: batch PTE-mapped large folios in gup_fast_pte_range() Yeoreum Yun

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=3a2d4135-f531-4797-8dd2-a2732a846e45@kernel.org \
    --to=david@kernel.org \
    --cc=aa9736195201@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=jgg@ziepe.ca \
    --cc=jhubbard@nvidia.com \
    --cc=liam@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ljs@kernel.org \
    --cc=mhocko@suse.com \
    --cc=peterx@redhat.com \
    --cc=riel@surriel.com \
    --cc=rppt@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=surenb@google.com \
    --cc=vbabka@kernel.org \
    --cc=yeoreum.yun@arm.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®