From fc38ca626f7140b8382bf63bf1c73cd840719c94 Mon Sep 17 00:00:00 2001 From: Marc Zyngier Date: Thu, 6 Jan 2022 10:01:01 +0000 Subject: [PATCH] ANDROID: KVM: arm64: Expose topup_hyp_memcache() to the rest of KVM In order to simplify the implementation of an EL2-only version of MMIO guard, expose topup_hyp_memcache() and simplify its usage by only requiring a vcpu. While we're at it, make free_hyp_memcache() visible in kvm_host.h Signed-off-by: Marc Zyngier Bug: 209580772 Change-Id: I4f54c57a9693cf7a3450f99fedc15ae32af09a31 Signed-off-by: Will Deacon --- arch/arm64/include/asm/kvm_host.h | 3 +++ arch/arm64/kvm/mmu.c | 10 +++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index c78baaad5661..c84aa9e6e680 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -125,6 +125,9 @@ static inline void __free_hyp_memcache(struct kvm_hyp_memcache *mc, free_fn(pop_hyp_memcache(mc, to_va), arg); } +void free_hyp_memcache(struct kvm_hyp_memcache *mc); +int topup_hyp_memcache(struct kvm_vcpu *vcpu); + struct kvm_vmid { /* The VMID generation used for the virt. memory system */ u64 vmid_gen; diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index 3662a9103fa8..4b7fbb0fc58f 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -820,13 +820,14 @@ void free_hyp_memcache(struct kvm_hyp_memcache *mc) kvm_host_va, NULL); } -static int topup_hyp_memcache(struct kvm_hyp_memcache *mc, - unsigned long min_pages) +int topup_hyp_memcache(struct kvm_vcpu *vcpu) { if (!is_protected_kvm_enabled()) return 0; - return __topup_hyp_memcache(mc, min_pages, hyp_mc_alloc_fn, + return __topup_hyp_memcache(&vcpu->arch.pkvm_memcache, + kvm_mmu_cache_min_pages(vcpu->kvm), + hyp_mc_alloc_fn, kvm_host_pa, NULL); } @@ -1161,7 +1162,6 @@ static int pkvm_host_donate_guest(u64 pfn, u64 gfn, struct kvm_vcpu *vcpu) static int pkvm_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, unsigned long hva) { - struct kvm_hyp_memcache *hyp_memcache = &vcpu->arch.pkvm_memcache; struct mm_struct *mm = current->mm; unsigned int flags = FOLL_FORCE | FOLL_HWPOISON | @@ -1173,7 +1173,7 @@ static int pkvm_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, u64 pfn; int ret; - ret = topup_hyp_memcache(hyp_memcache, kvm_mmu_cache_min_pages(kvm)); + ret = topup_hyp_memcache(vcpu); if (ret) return -ENOMEM;