[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[RFC] xen/arm: guard pages and overflow detection for vCPU stacks


  • To: xen-devel@xxxxxxxxxxxxxxxxxxxx
  • From: Gabriel Quintáns Souto <gabi.qs.mail@xxxxxxxxx>
  • Date: Sat, 28 Nov 2026 18:58:14 +0100
  • Arc-authentication-results: i=1; mx.google.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=cc:to:subject:message-id:date:from:mime-version:dkim-signature; bh=V6q8RxH9hE7iftoxV0Svz/fpN2S1O4VYF69KJrkSkiE=; fh=2MwiQ0NPPymAVGa17gJzacK0ckYPalt543saBDyqEgE=; b=RGtu7NRliWp+GuqG2aaQ6UDaGsUrtkopSnyDZMRPLjOPQbqz9XZ+UBB/CD6AIHjn2z bpMBnS8l2zB4+ClWkQAqXG6JKUSOCUYpTIMbSjhHre7pwcG0whMJoEUz9yXIGokGZZ63 2BAFCOtUOHZyXSPXBf5D9cXIWe8O0QxeO9zPCEy7qkT2+Fh6r3pv+mtM0dpLLy+LK3F5 Uv0cBxTXmqHvy7obCauSVKWXhvjNW0aDrv8d25ahA0xpjL2nP6CPU6eO/ZjBDHT+PTyi JTH1e086PdUO1md7F7PPW32iTM5/Ps9GerAPeHLt719M1pFdVA+6CGOUa5Od5gGMH3hw mmRQ==; darn=lists.xenproject.org
  • Arc-seal: i=1; a=rsa-sha256; t=1795888705; cv=none; d=google.com; s=arc-20260327; b=sEAkpx+sw+V/Ulo/4AiRvvYfl2f/A6aznty2eXUIqWrviVUpEgTPVUPxtgi8u2/Ncy KvfZEfgONtvNjp0uRENAegZEQwhbaF+Fyc8BN4a0b2aM0hVWQIzcWc3SENV1hdTnPGfQ WwlLn5OjdOdCXYsZJs/2W6efLwbpp7QbHU/1oZR92Qkm4x87iB1vXLHMKsqeZ9oNr0pA USimy67v8zewe34Mfd6fwKOLIHcHujh7QZvqhJp98m6s2u0ElwIQB0EcsRLhXx3eOKIK ZrQNvoFjvQoJbOKhpZ1i/EVu3dPNT64XwvWgbImcFnkxScq5ymUNLX273t1zmfpOauJh wHgg==
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=20260707 header.d=gmail.com header.i="@gmail.com" header.h="Content-Type:Cc:To:Subject:Message-ID:Date:From:MIME-Version"
  • Cc: sstabellini@xxxxxxxxxx, "Orzel, Michal" <michal.orzel@xxxxxxx>, bertrand.marquis@xxxxxxx, julien@xxxxxxx, Volodymyr_Babchuk@xxxxxxxx, stewart.hildebrand@xxxxxxx
  • Delivery-date: Sat, 28 Nov 2026 17:58:49 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Hi all,

In the "Stack checking on Arm" thread [1], Julien suggested, and
Stefano agreed, that we eventually want stack guards on Arm. As far
as I can see in current staging, nothing like this has landed yet.
This is complementary to the stack protector work [2].

I'd like to work on this, and agree on the approach before writing
patches.

Proposal:

Part 1: vCPU stacks in the vmap area, with a guard page

   arch_vcpu_create() keeps allocating STACK_ORDER physically
   contiguous pages, but switches from alloc_xenheap_pages() to
   alloc_domheap_pages(). It then maps them with __vmap(), asking for
   an alignment of 2 * STACK_SIZE. The vmap allocator always leaves
   at least one unmapped page below each allocation, so every stack
   gets a guard page right below it.

   The physical layout of the stack is the same as today. Only the
   virtual address changes. get_cpu_info(), show_trace() and
   guest_mode() mask with STACK_SIZE, and they keep working because
   the stack is still STACK_SIZE aligned.

   cpu0_boot_stack is only used until start_xen() switches to idle
   vCPU 0, so it stays as it is.

Part 2: Overflow detection on arm64

   On its own, a guard page turns an overflow into a recursive data
   abort, because entry.S pushes the frame on the same stack. I would
   follow what KVM does for the nVHE hypervisor [3][4]. Because the
   stack is aligned to twice its size, bit log2(STACK_SIZE) of SP is
   clear while SP is inside the stack and set once it has dropped
   below it. In the EL2h vectors, I'd test that bit before saving any
   state and without clobbering a GPR. On overflow, the handler
   switches to a small per-CPU overflow stack and panics. Traps from
   the guest go through the lower-EL vectors and start on an empty
   stack, and therefore skip the check and get no extra overhead.

   The bit test is the only reason for aligning to 2 * STACK_SIZE
   rather than just STACK_SIZE.

   Part 1 already covers arm32. For this part, I'd start with arm64
   and look at arm32 afterwards.

So far I've looked at what could break with a vmap'ed stack.

virt_to_page() only works on directmap addresses, but the only place
that uses it on a stack address is the free_xenheap_pages() in
arch_vcpu_destroy(), and that goes away anyway.

I didn't find anything that hands the physical address of a stack
buffer to hardware or firmware. Even if there were, the allocation
stays physically contiguous.

On arm32 each CPU has its own root table. prepare_secondary_mm()
copies all of CPU0's entries into it (except the domheap ones). The
vmap area is below 1GB, under a second-level table that all CPUs
share, so a stack mapped after the copy is visible on every CPU.

Two things I'd like your opinion on:

-  Aligning each stack to 64K costs up to 32K of extra VA per vCPU.
   The 1GB arm64 vmap area then fits about 16k stacks, shared with
   ioremap and the other vmap users. Is that acceptable, or would you
   prefer a dedicated region?
-  Always on for MMU builds, or behind a Kconfig option?

If the direction looks fine, I'll send part 1 first, and part 2 as a
separate series.

Best regards,
Gabriel

[1] https://lists.xenproject.org/archives/html/xen-devel/2024-07/msg01578.html
[2] be2a6a1096 ("xen: common: add ability to enable stack protector")
[3] Linux 1a919b17ef01 ("KVM: arm64: Add guard pages for pKVM
(protected nVHE) hypervisor stack")
[4] Linux 66de19fad9ef ("KVM: arm64: Detect and handle hypervisor
stack overflows")



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.