mirror of
https://github.com/hardkernel/linux.git
synced 2026-06-07 03:15:31 +09:00
ANDROID: KVM: arm64: pkvm: Wire MMIO guard hypercalls
Plumb in the hypercall interface to allow a guest to discover, enroll, map and unmap MMIO regions. Signed-off-by: Marc Zyngier <maz@kernel.org> Bug: 209580772 Change-Id: I0390456ffde8ceca351d3d8e82fd1dddeb747fac Signed-off-by: Will Deacon <willdeacon@google.com>
This commit is contained in:
committed by
Will Deacon
parent
f01af370af
commit
030481dc2d
@@ -105,6 +105,9 @@ static void handle_pvm_entry_hvc64(struct kvm_vcpu *host_vcpu, struct kvm_vcpu *
|
||||
u32 fn = smccc_get_function(shadow_vcpu);
|
||||
|
||||
switch (fn) {
|
||||
case ARM_SMCCC_VENDOR_HYP_KVM_MMIO_GUARD_MAP_FUNC_ID:
|
||||
pkvm_refill_memcache(shadow_vcpu, host_vcpu);
|
||||
break;
|
||||
case ARM_SMCCC_VENDOR_HYP_KVM_MEM_SHARE_FUNC_ID:
|
||||
fallthrough;
|
||||
case ARM_SMCCC_VENDOR_HYP_KVM_MEM_UNSHARE_FUNC_ID:
|
||||
@@ -297,6 +300,10 @@ static void handle_pvm_exit_hvc64(struct kvm_vcpu *host_vcpu, struct kvm_vcpu *s
|
||||
n = 4;
|
||||
break;
|
||||
|
||||
case ARM_SMCCC_VENDOR_HYP_KVM_MMIO_GUARD_MAP_FUNC_ID:
|
||||
n = 3;
|
||||
break;
|
||||
|
||||
/*
|
||||
* The rest are either blocked or handled by HYP, so we should
|
||||
* really never be here.
|
||||
|
||||
@@ -1109,6 +1109,31 @@ out_guest_err:
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool pkvm_install_ioguard_page(struct kvm_vcpu *vcpu, u64 *exit_code)
|
||||
{
|
||||
u32 retval = SMCCC_RET_SUCCESS;
|
||||
u64 ipa = smccc_get_arg1(vcpu);
|
||||
int ret;
|
||||
|
||||
ret = __pkvm_install_ioguard_page(vcpu, ipa);
|
||||
if (ret == -ENOMEM) {
|
||||
/*
|
||||
* We ran out of memcache, let's ask for more. Cancel
|
||||
* the effects of the HVC that took us here, and
|
||||
* forward the hypercall to the host for page donation
|
||||
* purposes.
|
||||
*/
|
||||
write_sysreg_el2(read_sysreg_el2(SYS_ELR) - 4, SYS_ELR);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ret)
|
||||
retval = SMCCC_RET_INVALID_PARAMETER;
|
||||
|
||||
smccc_set_retval(vcpu, retval, 0, 0, 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Handler for protected VM HVC calls.
|
||||
*
|
||||
@@ -1136,7 +1161,22 @@ bool kvm_handle_pvm_hvc64(struct kvm_vcpu *vcpu, u64 *exit_code)
|
||||
val[0] |= BIT(ARM_SMCCC_KVM_FUNC_HYP_MEMINFO);
|
||||
val[0] |= BIT(ARM_SMCCC_KVM_FUNC_MEM_SHARE);
|
||||
val[0] |= BIT(ARM_SMCCC_KVM_FUNC_MEM_UNSHARE);
|
||||
val[0] |= BIT(ARM_SMCCC_KVM_FUNC_MMIO_GUARD_INFO);
|
||||
val[0] |= BIT(ARM_SMCCC_KVM_FUNC_MMIO_GUARD_ENROLL);
|
||||
val[0] |= BIT(ARM_SMCCC_KVM_FUNC_MMIO_GUARD_MAP);
|
||||
val[0] |= BIT(ARM_SMCCC_KVM_FUNC_MMIO_GUARD_UNMAP);
|
||||
break;
|
||||
case ARM_SMCCC_VENDOR_HYP_KVM_MMIO_GUARD_ENROLL_FUNC_ID:
|
||||
set_bit(KVM_ARCH_FLAG_MMIO_GUARD, &vcpu->arch.pkvm.shadow_vm->arch.flags);
|
||||
val[0] = SMCCC_RET_SUCCESS;
|
||||
break;
|
||||
case ARM_SMCCC_VENDOR_HYP_KVM_MMIO_GUARD_MAP_FUNC_ID:
|
||||
return pkvm_install_ioguard_page(vcpu, exit_code);
|
||||
case ARM_SMCCC_VENDOR_HYP_KVM_MMIO_GUARD_UNMAP_FUNC_ID:
|
||||
if (__pkvm_remove_ioguard_page(vcpu, vcpu_get_reg(vcpu, 1)))
|
||||
val[0] = SMCCC_RET_SUCCESS;
|
||||
break;
|
||||
case ARM_SMCCC_VENDOR_HYP_KVM_MMIO_GUARD_INFO_FUNC_ID:
|
||||
case ARM_SMCCC_VENDOR_HYP_KVM_HYP_MEMINFO_FUNC_ID:
|
||||
if (smccc_get_arg1(vcpu) ||
|
||||
smccc_get_arg2(vcpu) ||
|
||||
|
||||
@@ -159,6 +159,10 @@ int kvm_hvc_call_handler(struct kvm_vcpu *vcpu)
|
||||
if (!kvm_vcpu_exit_hcall(vcpu, ARM_SMCCC_KVM_FUNC_MEM_UNSHARE, 3))
|
||||
return 0;
|
||||
break;
|
||||
case ARM_SMCCC_VENDOR_HYP_KVM_MMIO_GUARD_MAP_FUNC_ID:
|
||||
if (kvm_vm_is_protected(vcpu->kvm) && !topup_hyp_memcache(vcpu))
|
||||
val[0] = SMCCC_RET_SUCCESS;
|
||||
break;
|
||||
case ARM_SMCCC_TRNG_VERSION:
|
||||
case ARM_SMCCC_TRNG_FEATURES:
|
||||
case ARM_SMCCC_TRNG_GET_UUID:
|
||||
|
||||
Reference in New Issue
Block a user