KVM: arm64: Prevent re-finalisation of pKVM for a given CPU
authorWill Deacon <will@kernel.org>
Fri, 8 Oct 2021 13:58:38 +0000 (14:58 +0100)
committerMarc Zyngier <maz@kernel.org>
Mon, 11 Oct 2021 08:07:29 +0000 (09:07 +0100)
__pkvm_prot_finalize() completes the deprivilege of the host when pKVM
is in use by installing a stage-2 translation table for the calling CPU.

Issuing the hypercall multiple times for a given CPU makes little sense,
but in such a case just return early with -EPERM rather than go through
the whole page-table dance again.

Cc: Marc Zyngier <maz@kernel.org>
Cc: Quentin Perret <qperret@google.com>
Signed-off-by: Will Deacon <will@kernel.org>
Signed-off-by: Marc Zyngier <maz@kernel.org>
Link: https://lore.kernel.org/r/20211008135839.1193-6-will@kernel.org
arch/arm64/kvm/hyp/nvhe/mem_protect.c

index bacd493..cafe17e 100644 (file)
@@ -123,6 +123,9 @@ int __pkvm_prot_finalize(void)
        struct kvm_s2_mmu *mmu = &host_kvm.arch.mmu;
        struct kvm_nvhe_init_params *params = this_cpu_ptr(&kvm_init_params);
 
+       if (params->hcr_el2 & HCR_VM)
+               return -EPERM;
+
        params->vttbr = kvm_get_vttbr(mmu);
        params->vtcr = host_kvm.arch.vtcr;
        params->hcr_el2 |= HCR_VM;