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 <maz@kernel.org>
Bug: 209580772
Change-Id: I4f54c57a9693cf7a3450f99fedc15ae32af09a31
Signed-off-by: Will Deacon <willdeacon@google.com>
This commit is contained in:
Marc Zyngier
2022-01-06 10:01:01 +00:00
committed by Will Deacon
parent c1f264d4f0
commit c3e455cd33
2 changed files with 8 additions and 5 deletions

View File

@@ -124,6 +124,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;

View File

@@ -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;