Re: [PATCH v2 1/3] KVM: arm64: Check PGD alignment when creating a pVM

From: Fuad Tabba

Date: Thu Dec 03 2026 - 04:49:15 EST


Hi Vincent,

On Wed, 02 Dec 2026 20:16:38 +0000, Vincent Donnefort <vdonnefort@xxxxxxxxxx> wrote:
[...]
> > diff --git a/arch/arm64/kvm/hyp/nvhe/mem_protect.c b/arch/arm64/kvm/hyp/nvhe/mem_protect.c
[...]
> > @@ -186,7 +186,7 @@ static void *guest_s2_zalloc_pages_exact(size_t size)
> > {
> > void *addr = hyp_alloc_pages(&current_vm->pool, get_order(size));
> >
> > - WARN_ON(size != (PAGE_SIZE << get_order(size)));
> > + WARN_ON(!addr || size != (PAGE_SIZE << get_order(size)));
>
> Instead of adding to the WARN_ON, perhaps we could
>
> if (!addr)
> return NULL;

Will do.

[...]
> > diff --git a/arch/arm64/kvm/hyp/nvhe/pkvm.c b/arch/arm64/kvm/hyp/nvhe/pkvm.c
[...]
> > @@ -924,6 +924,10 @@ int __pkvm_init_vm(struct kvm *host_kvm, void __kern *pgd_hva)
> >
> > vm_size = pkvm_get_hyp_vm_size(nr_vcpus);
> > pgd_size = kvm_pgtable_stage2_pgd_size(host_mmu.arch.mmu.vtcr);
> > + if (!IS_ALIGNED((unsigned long)pgd_hva, pgd_size)) {
> > + ret = -EINVAL;
> > + goto err_unpin_kvm;
> > + }
>
> With this, map_donated_memory_noclear() is really just calling
> __pkvm_host_donate_hyp(). Could we remove it?
>
> Also, I wonder if it isn't better to first have
>
> pgd = kern_hyp_va(pgd_hva);
> if (!IS_ALIGNED(pgd....))
>
> to avoid casting a __kern annotated variable?

Sure, I'll add a patch after this one in v3 that removes the helper and
checks the translated pointer, to keep the fix small.

Cheers,
/fuad