ANDROID: BACKPORT: KVM: arm64: Introduce KVM_VM_TYPE_ARM_PROTECTED machine type for PVMs

Introduce a new virtual machine type, KVM_VM_TYPE_ARM_PROTECTED, which
specifies that the guest memory pages are to be unmapped from the host
stage-2 by the hypervisor.

Signed-off-by: Will Deacon <will@kernel.org>
[willdeacon@: Align KVM_VM_TYPE_ARM_PROTECTED value with android13 kernels]
Signed-off-by: Will Deacon <willdeacon@google.com>
Bug: 233587962
Change-Id: Iabcd03865aed4a41637597ac247897fd185bfc4d
This commit is contained in:
Will Deacon
2022-04-25 15:20:12 +00:00
committed by Will Deacon
parent 2818b69cdf
commit 52bf3ffd0b
5 changed files with 20 additions and 6 deletions

View File

@@ -16,7 +16,7 @@
#define HYP_MEMBLOCK_REGIONS 128
int pkvm_init_host_vm(struct kvm *kvm);
int pkvm_init_host_vm(struct kvm *kvm, unsigned long type);
int pkvm_create_hyp_vm(struct kvm *kvm);
void pkvm_destroy_hyp_vm(struct kvm *kvm);

View File

@@ -145,11 +145,14 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)
{
int ret;
if (type & ~KVM_VM_TYPE_MASK)
return -EINVAL;
ret = kvm_share_hyp(kvm, kvm + 1);
if (ret)
return ret;
ret = pkvm_init_host_vm(kvm);
ret = pkvm_init_host_vm(kvm, type);
if (ret)
goto err_unshare_kvm;

View File

@@ -681,9 +681,6 @@ int kvm_init_stage2_mmu(struct kvm *kvm, struct kvm_s2_mmu *mmu, unsigned long t
u64 mmfr0, mmfr1;
u32 phys_shift;
if (type & ~KVM_VM_TYPE_ARM_IPA_SIZE_MASK)
return -EINVAL;
phys_shift = KVM_VM_TYPE_ARM_IPA_SIZE(type);
if (is_protected_kvm_enabled()) {
phys_shift = kvm_ipa_limit;

View File

@@ -235,8 +235,16 @@ void pkvm_destroy_hyp_vm(struct kvm *host_kvm)
}
}
int pkvm_init_host_vm(struct kvm *host_kvm)
int pkvm_init_host_vm(struct kvm *host_kvm, unsigned long type)
{
mutex_init(&host_kvm->lock);
if (!(type & KVM_VM_TYPE_ARM_PROTECTED))
return 0;
if (!is_protected_kvm_enabled())
return -EINVAL;
host_kvm->arch.pkvm.enabled = true;
return 0;
}

View File

@@ -866,6 +866,12 @@ struct kvm_ppc_resize_hpt {
#define KVM_VM_TYPE_ARM_IPA_SIZE_MASK 0xffULL
#define KVM_VM_TYPE_ARM_IPA_SIZE(x) \
((x) & KVM_VM_TYPE_ARM_IPA_SIZE_MASK)
#define KVM_VM_TYPE_ARM_PROTECTED (1UL << 31)
#define KVM_VM_TYPE_MASK (KVM_VM_TYPE_ARM_IPA_SIZE_MASK | \
KVM_VM_TYPE_ARM_PROTECTED)
/*
* ioctls for /dev/kvm fds:
*/