[PATCH v2 15/18] KVM: arm64: Alloc pkvm_hyp_vm using pKVM heap allocator

Vincent Donnefort vdonnefort at google.com
Wed Jul 15 05:55:23 PDT 2026


On Wed, Jul 15, 2026 at 01:33:00PM +0100, Fuad Tabba wrote:
> On Mon, 6 Jul 2026 at 18:54, 'Vincent Donnefort' via kernel-team
> <kernel-team at android.com> wrote:
> 
> ...
> 
> > --- a/arch/arm64/kvm/pkvm.c
> > +++ b/arch/arm64/kvm/pkvm.c
> > @@ -191,8 +191,8 @@ static int __pkvm_create_hyp_vcpu(struct kvm_vcpu *vcpu)
> >   */
> >  static int __pkvm_create_hyp_vm(struct kvm *kvm)
> >  {
> > -       size_t pgd_sz, hyp_vm_sz;
> > -       void *pgd, *hyp_vm;
> > +       size_t pgd_sz;
> > +       void *pgd;
> >         int ret;
> >
> >         if (kvm->created_vcpus < 1)
> > @@ -209,28 +209,15 @@ static int __pkvm_create_hyp_vm(struct kvm *kvm)
> >         if (!pgd)
> >                 return -ENOMEM;
> >
> > -       /* Allocate memory to donate to hyp for vm and vcpu pointers. */
> > -       hyp_vm_sz = PAGE_ALIGN(size_add(PKVM_HYP_VM_SIZE,
> > -                                       size_mul(sizeof(void *),
> > -                                                kvm->created_vcpus)));
> > -       hyp_vm = alloc_pages_exact(hyp_vm_sz, GFP_KERNEL_ACCOUNT);
> > -       if (!hyp_vm) {
> > -               ret = -ENOMEM;
> > -               goto free_pgd;
> > -       }
> > -
> > -       /* Donate the VM memory to hyp and let hyp initialize it. */
> > -       ret = kvm_call_hyp_nvhe(__pkvm_init_vm, kvm, hyp_vm, pgd);
> > +       ret = pkvm_call_hyp_req(__pkvm_init_vm, kvm, pgd);
> 
> Sashiko might be right on the memcg point: hyp_vm used to be
> GFP_KERNEL_ACCOUNT and now comes from the heap unaccounted, while pgd
> next to it is still accounted, so it's inconsistent.

Yep that is correct but there is no way around that:

 * Donated memory can now be shared be shared by several VM (or other parts of
   the hypervisor)

 * Donated memory is also not reclaimed until the shrinker fires.

So we don't really have a way to account for that meta-data anymore.

(I should at least mention this in the commit message)

> 
> If we do want to fix it, would it go in pkvm_hyp_topup() to cover all
> consumers rather than here?
> 
> Cheers,
> /fuad



More information about the linux-arm-kernel mailing list