|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [RFC] xen/arm: guard pages and overflow detection for vCPU stacks
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")
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |