From 0dd604b38eab0979a4d7dc6ab5b5ad3f36caa5da Mon Sep 17 00:00:00 2001 From: Will Deacon Date: Thu, 7 Jul 2022 15:51:26 +0100 Subject: [PATCH] Revert "ANDROID: KVM: arm64: Add MEMINFO and {UN,}SHARE hypercalls for protected guests" This reverts commit da4c4dc33af447d582e28ab00465b0df239c04b1. Bug: 233587962 Signed-off-by: Will Deacon Change-Id: I5f812a7f92fc3762cb455b779f56aedac2e2cb83 --- arch/arm64/kvm/hyp/include/nvhe/pkvm.h | 2 +- arch/arm64/kvm/hyp/nvhe/hyp-main.c | 10 --- arch/arm64/kvm/hyp/nvhe/pkvm.c | 100 +------------------------ arch/arm64/kvm/hyp/nvhe/switch.c | 11 +++ include/linux/arm-smccc.h | 21 ------ 5 files changed, 13 insertions(+), 131 deletions(-) diff --git a/arch/arm64/kvm/hyp/include/nvhe/pkvm.h b/arch/arm64/kvm/hyp/include/nvhe/pkvm.h index bdaacd70b9fe..30922f99e2f8 100644 --- a/arch/arm64/kvm/hyp/include/nvhe/pkvm.h +++ b/arch/arm64/kvm/hyp/include/nvhe/pkvm.h @@ -64,7 +64,7 @@ int kvm_check_pvm_sysreg_table(void); void pkvm_reset_vcpu(struct kvm_vcpu *vcpu); -bool kvm_handle_pvm_hvc64(struct kvm_vcpu *vcpu, u64 *exit_code); +bool pkvm_handle_hvc64(struct kvm_vcpu *vcpu); struct kvm_vcpu *pvm_mpidr_to_vcpu(struct kvm_shadow_vm *vm, unsigned long mpidr); diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-main.c b/arch/arm64/kvm/hyp/nvhe/hyp-main.c index 60ad5dd14f0e..59f289f708f4 100644 --- a/arch/arm64/kvm/hyp/nvhe/hyp-main.c +++ b/arch/arm64/kvm/hyp/nvhe/hyp-main.c @@ -77,11 +77,6 @@ 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_MEM_SHARE_FUNC_ID: - fallthrough; - case ARM_SMCCC_VENDOR_HYP_KVM_MEM_UNSHARE_FUNC_ID: - vcpu_set_reg(shadow_vcpu, 0, SMCCC_RET_SUCCESS); - break; default: handle_pvm_entry_psci(host_vcpu, shadow_vcpu); break; @@ -263,11 +258,6 @@ static int get_num_hvc_args(struct kvm_vcpu *vcpu) case PSCI_0_2_FN64_CPU_SUSPEND: return 0; - case ARM_SMCCC_VENDOR_HYP_KVM_MEM_SHARE_FUNC_ID: - fallthrough; - case ARM_SMCCC_VENDOR_HYP_KVM_MEM_UNSHARE_FUNC_ID: - return 3; - /* The rest are either blocked or handled by hyp. */ default: return -1; diff --git a/arch/arm64/kvm/hyp/nvhe/pkvm.c b/arch/arm64/kvm/hyp/nvhe/pkvm.c index 811cb17841dd..4b71cac88891 100644 --- a/arch/arm64/kvm/hyp/nvhe/pkvm.c +++ b/arch/arm64/kvm/hyp/nvhe/pkvm.c @@ -957,89 +957,7 @@ static bool pkvm_handle_psci(struct kvm_vcpu *vcpu) return pvm_psci_not_supported(vcpu); } -static u64 __pkvm_memshare_page_req(struct kvm_vcpu *vcpu, u64 ipa) -{ - u64 elr; - - /* Fake up a data abort (Level 3 translation fault on write) */ - vcpu->arch.fault.esr_el2 = (u32)ESR_ELx_EC_DABT_LOW << ESR_ELx_EC_SHIFT | - ESR_ELx_WNR | ESR_ELx_FSC_FAULT | - FIELD_PREP(ESR_ELx_FSC_LEVEL, 3); - - /* Shuffle the IPA around into the HPFAR */ - vcpu->arch.fault.hpfar_el2 = (ipa >> 8) & HPFAR_MASK; - - /* This is a virtual address. 0's good. Let's go with 0. */ - vcpu->arch.fault.far_el2 = 0; - - /* Rewind the ELR so we return to the HVC once the IPA is mapped */ - elr = read_sysreg(elr_el2); - elr -=4; - write_sysreg(elr, elr_el2); - - return ARM_EXCEPTION_TRAP; -} - -static bool pkvm_memshare_call(struct kvm_vcpu *vcpu, u64 *exit_code) -{ - u64 ipa = smccc_get_arg1(vcpu); - u64 arg2 = smccc_get_arg2(vcpu); - u64 arg3 = smccc_get_arg3(vcpu); - int err; - - if (arg2 || arg3) - goto out_guest_err; - - err = __pkvm_guest_share_host(vcpu, ipa); - switch (err) { - case 0: - /* Success! Now tell the host. */ - goto out_host; - case -EFAULT: - /* - * Convert the exception into a data abort so that the page - * being shared is mapped into the guest next time. - */ - *exit_code = __pkvm_memshare_page_req(vcpu, ipa); - goto out_host; - } - -out_guest_err: - smccc_set_retval(vcpu, SMCCC_RET_INVALID_PARAMETER, 0, 0, 0); - return true; - -out_host: - return false; -} - -static bool pkvm_memunshare_call(struct kvm_vcpu *vcpu) -{ - u64 ipa = smccc_get_arg1(vcpu); - u64 arg2 = smccc_get_arg2(vcpu); - u64 arg3 = smccc_get_arg3(vcpu); - int err; - - if (arg2 || arg3) - goto out_guest_err; - - err = __pkvm_guest_unshare_host(vcpu, ipa); - if (err) - goto out_guest_err; - - return false; - -out_guest_err: - smccc_set_retval(vcpu, SMCCC_RET_INVALID_PARAMETER, 0, 0, 0); - return true; -} - -/* - * Handler for protected VM HVC calls. - * - * Returns true if the hypervisor has handled the exit, and control should go - * back to the guest, or false if it hasn't. - */ -bool kvm_handle_pvm_hvc64(struct kvm_vcpu *vcpu, u64 *exit_code) +bool pkvm_handle_hvc64(struct kvm_vcpu *vcpu) { u32 fn = smccc_get_function(vcpu); u64 val[4] = { SMCCC_RET_NOT_SUPPORTED }; @@ -1057,23 +975,7 @@ bool kvm_handle_pvm_hvc64(struct kvm_vcpu *vcpu, u64 *exit_code) break; case ARM_SMCCC_VENDOR_HYP_KVM_FEATURES_FUNC_ID: val[0] = BIT(ARM_SMCCC_KVM_FUNC_FEATURES); - 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); break; - case ARM_SMCCC_VENDOR_HYP_KVM_HYP_MEMINFO_FUNC_ID: - if (smccc_get_arg1(vcpu) || - smccc_get_arg2(vcpu) || - smccc_get_arg3(vcpu)) { - val[0] = SMCCC_RET_INVALID_PARAMETER; - } else { - val[0] = PAGE_SIZE; - } - break; - case ARM_SMCCC_VENDOR_HYP_KVM_MEM_SHARE_FUNC_ID: - return pkvm_memshare_call(vcpu, exit_code); - case ARM_SMCCC_VENDOR_HYP_KVM_MEM_UNSHARE_FUNC_ID: - return pkvm_memunshare_call(vcpu); default: return pkvm_handle_psci(vcpu); } diff --git a/arch/arm64/kvm/hyp/nvhe/switch.c b/arch/arm64/kvm/hyp/nvhe/switch.c index 8d18560ee015..261137276293 100644 --- a/arch/arm64/kvm/hyp/nvhe/switch.c +++ b/arch/arm64/kvm/hyp/nvhe/switch.c @@ -192,6 +192,17 @@ static bool kvm_handle_pvm_fpsimd(struct kvm_vcpu *vcpu, u64 *exit_code) return kvm_hyp_handle_fpsimd(vcpu, exit_code); } +/* + * Handler for protected VM HVC calls. + * + * Returns true if the hypervisor has handled the exit, and control should go + * back to the guest, or false if it hasn't. + */ +static bool kvm_handle_pvm_hvc64(struct kvm_vcpu *vcpu, u64 *exit_code) +{ + return pkvm_handle_hvc64(vcpu); +} + static const exit_handler_fn hyp_exit_handlers[] = { [0 ... ESR_ELx_EC_MAX] = NULL, [ESR_ELx_EC_CP15_32] = kvm_hyp_handle_cp15_32, diff --git a/include/linux/arm-smccc.h b/include/linux/arm-smccc.h index 25c576a910df..220c8c60e021 100644 --- a/include/linux/arm-smccc.h +++ b/include/linux/arm-smccc.h @@ -112,9 +112,6 @@ /* KVM "vendor specific" services */ #define ARM_SMCCC_KVM_FUNC_FEATURES 0 #define ARM_SMCCC_KVM_FUNC_PTP 1 -#define ARM_SMCCC_KVM_FUNC_HYP_MEMINFO 2 -#define ARM_SMCCC_KVM_FUNC_MEM_SHARE 3 -#define ARM_SMCCC_KVM_FUNC_MEM_UNSHARE 4 #define ARM_SMCCC_KVM_FUNC_FEATURES_2 127 #define ARM_SMCCC_KVM_NUM_FUNCS 128 @@ -137,24 +134,6 @@ ARM_SMCCC_OWNER_VENDOR_HYP, \ ARM_SMCCC_KVM_FUNC_PTP) -#define ARM_SMCCC_VENDOR_HYP_KVM_HYP_MEMINFO_FUNC_ID \ - ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \ - ARM_SMCCC_SMC_64, \ - ARM_SMCCC_OWNER_VENDOR_HYP, \ - ARM_SMCCC_KVM_FUNC_HYP_MEMINFO) - -#define ARM_SMCCC_VENDOR_HYP_KVM_MEM_SHARE_FUNC_ID \ - ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \ - ARM_SMCCC_SMC_64, \ - ARM_SMCCC_OWNER_VENDOR_HYP, \ - ARM_SMCCC_KVM_FUNC_MEM_SHARE) - -#define ARM_SMCCC_VENDOR_HYP_KVM_MEM_UNSHARE_FUNC_ID \ - ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \ - ARM_SMCCC_SMC_64, \ - ARM_SMCCC_OWNER_VENDOR_HYP, \ - ARM_SMCCC_KVM_FUNC_MEM_UNSHARE) - /* ptp_kvm counter type ID */ #define KVM_PTP_VIRT_COUNTER 0 #define KVM_PTP_PHYS_COUNTER 1