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.

Bug: 209580772
Change-Id: I4f54c57a9693cf7a3450f99fedc15ae32af09a31
Signed-off-by: Marc Zyngier <maz@kernel.org>
[tabba@: original patch did the same for free_hyp_memcache(), but
it's already exposed]
Signed-off-by: Fuad Tabba <tabba@google.com>
Signed-off-by: Quentin Perret <qperret@google.com>
This commit is contained in:
Marc Zyngier
2022-01-06 10:01:01 +00:00
committed by Quentin Perret
parent 2b8c3bb99b
commit d8bf88fa79
2 changed files with 6 additions and 5 deletions

View File

@@ -128,7 +128,7 @@ static inline void __free_hyp_memcache(struct kvm_hyp_memcache *mc,
}
void free_hyp_memcache(struct kvm_hyp_memcache *mc);
int topup_hyp_memcache(struct kvm_hyp_memcache *mc, unsigned long min_pages);
int topup_hyp_memcache(struct kvm_vcpu *vcpu);
struct kvm_vmid {
atomic64_t id;

View File

@@ -878,12 +878,14 @@ void free_hyp_memcache(struct kvm_hyp_memcache *mc)
kvm_host_va, NULL);
}
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);
}
@@ -1234,7 +1236,6 @@ static int insert_ppage(struct kvm *kvm, struct kvm_pinned_page *ppage)
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_HWPOISON | FOLL_LONGTERM | FOLL_WRITE;
struct kvm_pinned_page *ppage;
@@ -1243,7 +1244,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;