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: 357781595
Change-Id: I4f54c57a9693cf7a3450f99fedc15ae32af09a31
Signed-off-by: Marc Zyngier <maz@kernel.org>
Signed-off-by: Fuad Tabba <tabba@google.com>
This commit is contained in:
Marc Zyngier
2022-01-06 10:01:01 +00:00
committed by Keir Fraser
parent 4bc142f9c2
commit 38e040c134
2 changed files with 6 additions and 6 deletions
+1 -1
View File
@@ -139,7 +139,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;
+5 -5
View File
@@ -1113,12 +1113,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->arch.mmu),
hyp_mc_alloc_fn,
kvm_host_pa, NULL);
}
@@ -1460,19 +1462,17 @@ static int pkvm_host_map_guest(u64 pfn, u64 gfn)
static int pkvm_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,
struct kvm_memory_slot *memslot)
{
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;
struct kvm *kvm = vcpu->kvm;
struct kvm_s2_mmu *mmu = &kvm->arch.mmu;
struct page *page;
gfn_t gfn = fault_ipa >> PAGE_SHIFT;
unsigned long hva = gfn_to_hva_memslot_prot(memslot, gfn, NULL);
u64 pfn;
int ret;
ret = topup_hyp_memcache(hyp_memcache, kvm_mmu_cache_min_pages(mmu));
ret = topup_hyp_memcache(vcpu);
if (ret)
return -ENOMEM;