Re: [PATCH v2 2/3] KVM: arm64: Align the pKVM selftest VM's stage-2 PGD
From: Vincent Donnefort
Date: Wed Dec 02 2026 - 15:26:47 EST
On Thu, Nov 05, 2026 at 07:56:05AM +0000, Fuad Tabba wrote:
> With CONFIG_NVHE_EL2_DEBUG, pKVM init sets up a selftest VM whose PGD is
> the start of its 32-page block. That block is the first allocation out
> of the hyp reserve, which falls back to page alignment when its
> PMD-aligned allocation fails (512M on a 64K host).
>
> A PGD of concatenated tables must be naturally aligned, or the VM's pool
> never coalesces it into a block hyp_alloc_pages() can return. So when
> the reserve isn't aligned to the PGD's size, the allocation in
> guest_s2_zalloc_pages_exact() fails and pKVM init panics. A 64K host
> with a 44-bit PA has a four-page PGD, and on a 1G QEMU VM the reserve
> landed at 0x7fae0000.
>
> Take the aligned pages inside the block instead. The pages either side
> of it go to the memcache and the pool. The PGD is at most 16 pages, so
> it always fits.
>
> Fixes: 48d5645072930 ("KVM: arm64: Extend pKVM selftest for np-guests")
> Signed-off-by: Fuad Tabba <fuad.tabba@xxxxxxxxx>
> ---
> arch/arm64/kvm/hyp/nvhe/pkvm.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/arch/arm64/kvm/hyp/nvhe/pkvm.c b/arch/arm64/kvm/hyp/nvhe/pkvm.c
> index 03e530e15b4a2..820baf9ff74a2 100644
> --- a/arch/arm64/kvm/hyp/nvhe/pkvm.c
> +++ b/arch/arm64/kvm/hyp/nvhe/pkvm.c
> @@ -847,10 +847,14 @@ struct pkvm_hyp_vcpu *init_selftest_vm(void *virt)
> {
> struct hyp_page *p = hyp_virt_to_page(virt);
> unsigned long min_pages, seeded = 0;
> + void *pgd;
> int i;
>
> selftest_vm.kvm.arch.mmu.vtcr = host_mmu.arch.mmu.vtcr;
> - WARN_ON(kvm_guest_prepare_stage2(&selftest_vm, virt));
> +
> + /* A concatenated PGD must be naturally aligned for the pool to coalesce it. */
> + pgd = PTR_ALIGN(virt, kvm_pgtable_stage2_pgd_size(selftest_vm.kvm.arch.mmu.vtcr));
> + WARN_ON(kvm_guest_prepare_stage2(&selftest_vm, pgd));
>
> /*
> * Mirror pkvm_refill_memcache() for the share/donate pre-checks;
> --
> 2.47.3
>
I believe the patch from the THPs series where I make this selftest an HVC and
allocate that memory with __get_free_pages() [1] fixes this issue.
If this one doesn't get backported, perhaps this isn't necessary?
[1] https://lore.kernel.org/all/20261130155710.2371874-6-vdonnefort@xxxxxxxxxx/
--
Vincent