[PATCH 3/3] arm64: gcs: Do not map the guarded control stack as THP

Catalin Marinas catalin.marinas at arm.com
Fri Feb 20 06:05:31 PST 2026


The default GCS size allocated on first prctl() for the main thread or
subsequently on clone() is either half of RLIMIT_STACK or half of a
thread's stack size. Both of these are likely to be suitable for a THP
allocation and the kernel is more aggressive in creating such mappings.
However, it does not make much sense to use a huge page as it didn't
make sense for the normal stacks either. See commit c4608d1bf7c6 ("mm:
mmap: map MAP_STACK to VM_NOHUGEPAGE").

Force VM_NOHUGEPAGE when allocating/mapping the GCS. As per commit
7190b3c8bd2b ("mm: mmap: map MAP_STACK to VM_NOHUGEPAGE only if THP is
enabled"), only pass this flag if TRANSPARENT_HUGEPAGE is enabled as not
to confuse CRIU tools.

While at it, use the PROT_WRITE prot argument rather than the VM_WRITE
flag when calling do_mmap().

Signed-off-by: Catalin Marinas <catalin.marinas at arm.com>
Cc: Will Deacon <will at kernel.org>
Cc: Mark Brown <broonie at kernel.org>
Cc: David Hildenbrand <david at kernel.org>
---
 arch/arm64/mm/gcs.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/arch/arm64/mm/gcs.c b/arch/arm64/mm/gcs.c
index 6e93f78de79b..bbdb62ae47cd 100644
--- a/arch/arm64/mm/gcs.c
+++ b/arch/arm64/mm/gcs.c
@@ -13,15 +13,19 @@
 static unsigned long alloc_gcs(unsigned long addr, unsigned long size)
 {
 	int flags = MAP_ANONYMOUS | MAP_PRIVATE;
+	vm_flags_t vm_flags = VM_SHADOW_STACK;
 	struct mm_struct *mm = current->mm;
 	unsigned long mapped_addr, unused;
 
 	if (addr)
 		flags |= MAP_FIXED_NOREPLACE;
 
+	if (IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE))
+		vm_flags |= VM_NOHUGEPAGE;
+
 	mmap_write_lock(mm);
-	mapped_addr = do_mmap(NULL, addr, size, PROT_READ, flags,
-			      VM_SHADOW_STACK | VM_WRITE, 0, &unused, NULL);
+	mapped_addr = do_mmap(NULL, addr, size, PROT_READ | PROT_WRITE,
+			      flags, vm_flags, 0, &unused, NULL);
 	mmap_write_unlock(mm);
 
 	return mapped_addr;



More information about the linux-arm-kernel mailing list