KVM: arm64: Don't leak stage-2 page-table if VM fails to init under pKVM

If pkvm_init_host_vm() fails, we should free the stage-2 page-table
previously allocated by kvm_init_stage2_mmu().

Cc: Fuad Tabba <tabba@google.com>
Reviewed-by: Fuad Tabba <tabba@google.com>
Tested-by: Fuad Tabba <tabba@google.com>
Tested-by: Mostafa Saleh <smostafa@google.com>
Fixes: 07aeb70707 ("KVM: arm64: Reserve pKVM handle during pkvm_init_host_vm()")
Signed-off-by: Will Deacon <will@kernel.org>
Link: https://patch.msgid.link/20260330144841.26181-3-will@kernel.org
Signed-off-by: Marc Zyngier <maz@kernel.org>
master
Will Deacon 2026-03-30 15:48:03 +01:00 committed by Marc Zyngier
parent 660b208e8b
commit 5e66f723d4
1 changed files with 3 additions and 1 deletions

View File

@ -236,7 +236,7 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)
*/
ret = pkvm_init_host_vm(kvm);
if (ret)
goto err_free_cpumask;
goto err_uninit_mmu;
}
kvm_vgic_early_init(kvm);
@ -252,6 +252,8 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)
return 0;
err_uninit_mmu:
kvm_uninit_stage2_mmu(kvm);
err_free_cpumask:
free_cpumask_var(kvm->arch.supported_cpus);
err_unshare_kvm: