diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index 0ab00666670d..6e63a0cb76f1 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -1162,6 +1162,7 @@ static inline bool __vcpu_write_sys_reg_to_cpu(u64 val, int reg) struct kvm_vm_stat { struct kvm_vm_stat_generic generic; atomic64_t protected_hyp_mem; + atomic64_t protected_shared_mem; }; struct kvm_vcpu_stat { diff --git a/arch/arm64/kvm/guest.c b/arch/arm64/kvm/guest.c index 0b797ed6f41b..bff8c1212f75 100644 --- a/arch/arm64/kvm/guest.c +++ b/arch/arm64/kvm/guest.c @@ -32,6 +32,7 @@ const struct _kvm_stats_desc kvm_vm_stats_desc[] = { KVM_GENERIC_VM_STATS(), STATS_DESC_ICOUNTER(VM, protected_hyp_mem), + STATS_DESC_ICOUNTER(VM, protected_shared_mem), }; const struct kvm_stats_header kvm_vm_stats_header = { diff --git a/arch/arm64/kvm/hypercalls.c b/arch/arm64/kvm/hypercalls.c index b0e9975293d4..26e1f554f430 100644 --- a/arch/arm64/kvm/hypercalls.c +++ b/arch/arm64/kvm/hypercalls.c @@ -85,6 +85,8 @@ static bool kvm_smccc_default_allowed(u32 func_id) case ARM_SMCCC_VERSION_FUNC_ID: case ARM_SMCCC_ARCH_FEATURES_FUNC_ID: case ARM_SMCCC_VENDOR_HYP_KVM_MMIO_GUARD_MAP_FUNC_ID: + case ARM_SMCCC_VENDOR_HYP_KVM_MEM_SHARE_FUNC_ID: + case ARM_SMCCC_VENDOR_HYP_KVM_MEM_UNSHARE_FUNC_ID: return true; default: /* PSCI 0.2 and up is in the 0:0x1f range */ @@ -396,6 +398,16 @@ int kvm_smccc_call_handler(struct kvm_vcpu *vcpu) pkvm_host_reclaim_page(vcpu->kvm, smccc_get_arg1(vcpu)); val[0] = SMCCC_RET_SUCCESS; break; + case ARM_SMCCC_VENDOR_HYP_KVM_MEM_SHARE_FUNC_ID: + case ARM_SMCCC_VENDOR_HYP_KVM_MEM_UNSHARE_FUNC_ID: + if (!kvm_vm_is_protected(vcpu->kvm)) + break; + atomic64_add( + func_id == ARM_SMCCC_VENDOR_HYP_KVM_MEM_SHARE_FUNC_ID ? + PAGE_SIZE : -PAGE_SIZE, + &vcpu->kvm->stat.protected_shared_mem); + val[0] = SMCCC_RET_SUCCESS; + break; case ARM_SMCCC_TRNG_VERSION: case ARM_SMCCC_TRNG_FEATURES: case ARM_SMCCC_TRNG_GET_UUID: